aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference between innerclass and nested class?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "difference between innerclass and nested class??" Watch "difference between innerclass and nested class??" New topic
Author

difference between innerclass and nested class??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
hi ,

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

thanks
sri


Thanks & Regards<br /> <br />-Srikanth
L.A. Nilsson
Greenhorn

Joined: Oct 17, 2005
Posts: 5
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 ]
Ashwin Kumar
Greenhorn

Joined: Oct 13, 2005
Posts: 27
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.


SCJP 1.4<br />SCBCD 5.0<br />SCWCD 1.4 (Preparing)
srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
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

Joined: Jul 28, 2005
Posts: 252
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

Joined: Jul 28, 2005
Posts: 252
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 ]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Hope you are not confusing like me....
[ October 18, 2005: Message edited by: Akhil Trivedi ]

Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
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

Joined: Jun 22, 2005
Posts: 1526
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

Joined: Jun 22, 2005
Posts: 1526
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

Joined: Jul 28, 2005
Posts: 252
thanks a lot akhil....

thank u very much...


thanks
sri
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

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

Joined: Oct 20, 2005
Posts: 257

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.
Patrick Punty
Greenhorn

Joined: Jul 01, 2005
Posts: 24
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between innerclass and nested class??