Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

an interview question

 
Ranch Hand
Posts: 3851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of my friend had this question in interview :
what is the difference b/w inner class & nested class .

well , i just read a chapter of inner class from K&B cirtification book and i think the answer is : there is no difference b/w inner class & nested class but if we mark inner class as a static then it would be called as a top level nested class it would not be technically an inner class .

is the answer is correct ???

after this if suppose interviewer ask that why they are technically not be called as a inner class afterall it is inside the curly braces of outer class .

then what should be the answer ???

please reply ...

thanks a lot
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

suppose interviewer ask that why they are technically not be called as a inner class afterall it is inside the curly braces of outer class.



An instance of a static nested class is not associated with an instance of an outer class.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


what is the difference b/w inner class & nested class


Semantics. A nested class is any class that is defined within another class (i.e. it is a member of another class). An inner class is just a non-static nested class.

Why knowing this distinction (rather than, say, understanding the access difference between a static and non-static inner class) has any bearing on being able to engineer software using Java is the really hard question...

[ January 12, 2005: Message edited by: Paul Sturrock ]
[ January 12, 2005: Message edited by: Paul Sturrock ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well , i just read a chapter of inner class from K&B cirtification book and i think the answer is : there is no difference b/w inner class & nested class but if we mark inner class as a static then it would be called as a top level nested class it would not be technically an inner class .

is the answer is correct ???


Well from what you just wrote there is a difference, technically, so I'm not sure what you mean.

Note that the egregiously silly term "top-level nested class" was removed from Sun's terminology several years ago when JLS second edition came out. (Unfortunately not everyone realized this right away, including K & B.) The terms "top-level" and "nested" are mutually exclusive. All classes are either top-level or nested (not both). All nested classes are either static nested classes (also known as static member classes), or inner classes (any nested class that's not static). Inner classes are either non-static member classes, local classes, or anonymous classes.

Why knowing this distinction (rather than, say, understanding the access difference between a static and non-static inner class) has any bearing on being able to engineer software using Java is the really hard question...

Well, if you ever consult the Java Language Specification, it's very helpful to have a correct understanding of the terms as the JSL defines them and uses them. The JLS uses terminology very precisely, and programmers need to do so as well in order to understand it correctly.

Having said that, I think the original question makes a rather poor interview question, because many otherwise excellent programmers would answer incorrectly due to the large amount of contradictory information which can be found in Java books. Sun made a mess of this by not using their terminology consistently when they first introduced nested classes (not in the JLS - it was a document known both as the Inner Classes Specification, and the Nested Classes Specification, which indicates the basic problem). They've cleaned up their mess since then, mostly, but there are still many people who learned different terminology.
[ January 12, 2005: Message edited by: Jim Yingst ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Well, if you ever consult the Java Language Specification, it's very helpful to have a correct understanding of the terms as the JSL defines them and uses them. The JLS uses terminology very precisely, and programmers need to do so as well in order to understand it correctly.


OK. I concede my response was somewhat coloured by what I see as a irritating type of interview question: the type which tries to find out if you can remember the JLS off by heart (something which someone with no real grasp of programming, but a lot of time could do), rather than a more useful one which tries to find out if you understand how making an inner class static affects how it can be accessed. I've also never liked describing an inner class using a different name simply because its been made static. I can't help but feel that just makes it difficult for beginners.
 
I can't take it! You are too smart for me! Here is the tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic