• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference between innerclass and nested class??

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,

can anyone give me the differnce between inner class and nested class???

thanks
sri
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An inner class is a nonstatic nested class. Thus,

All inner classes are nested classes.
Some nested classes are inner classes.

"Like other members, a nested class can be declared static (or not). A static nested class is called just that: a static nested class. A nonstatic nested class is called an inner class."

Source:


Java tutorial, Nested Classes
[ October 18, 2005: Message edited by: L.A. Nilsson ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think...
Non-Static Inner Class - Inner Class
Static Inner Class - Nested Class

A Nested class doesnt have the privileges of accessing outer class members (including private).

Some one correct me if I am wrong.
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fundamentally, an inner class is the same as any other class, but is declared inside (that is, between the opening and closing curly braces of) some other class. In fact, you can declare nested classes in any block, including blocks that are part of a method.

so how can we say all inner are nested classes...

please can anyone give me the exact difference??
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
frnds this is what i infer after going through a mock question of inner class...

a nested class is one that is declared inside a class or an interface ...
if that doesnt have a name then it can be anonymous class....if has then its a non-anonymous class...if that is not inside any method then its a member class..and if its non-static then its an inner class.....

please clarify ..
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anonymous class be declared inside a method??? If a nested class does not have a name, then it can not be called a local class even if it is declared inside of a block. Therefore, an anonymous class is never called a local class

please explain me the bold written sentence .......
[ October 18, 2005: Message edited by: srikanth reddy ]
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope you are not confusing like me....
[ October 18, 2005: Message edited by: Akhil Trivedi ]
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks akhil...one more doubt is cleared..,,but my doubt regarding anonymous classes still remains ..whether they cud be called local class or not....plz clarify
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Srikanth, I think i really need to read JLS before answering you anything more. Check it out even i am going to do the same here. Good luck! Thanks, for now i know this is one more area where I need to concentrate.
[ October 18, 2005: Message edited by: Akhil Trivedi ]
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srikanth! I am back.
JLS Says...

NESTED CLASS
"A nested class is... any class whose declaration occurs... within the body of another class or interface. "


LOCAL CLASS
"A local class is a nested class... that is NOT a member of any class and that has a name. ... "

Point to be noted... A local class has a name.

ANONYMOUS CLASS
"An anonymous class declaration is automatically derived from a class instance creation expression by the compiler..."

An anonymous class can NOT be called a local class because local class must have a name and anonymous class are assumed to be nameless.



Correct me if I am wrong.
 
srikanth reddy
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot akhil....

thank u very much...


thanks
sri
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Some one told that it is possible to run the Java Program without using Java method.

I don't know how.

Any one could tell that.

if it is so, why to place main in to the program.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,

there is a correction in the last posted question.

that is

without using the main method in Java Program one can run ,.........
please make notice of it.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi j rangavallika ,

By using static block of code one can run a java program with out using main method, but to what extent the static code has power I am not aware of. Anyone plz confirm, and resolve my querry about static block's Power.

Thanks
Patrick
 
reply
    Bookmark Topic Watch Topic
  • New Topic