File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Local vs Inner Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Local vs Inner" Watch "Local vs Inner" New topic
Author

Local vs Inner

Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
Can anyone explain to me what's the difference between local and inner classes? I was unable to find an explanation.
Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
Hi my understanding of this is that a local class is the same as a local veriable in that you create the class inside a method and the life cycle of that class is only in the scope of the method. Inner class is outside any method but within the scope of a class.
Hope that helps...


Martyn...<br /> <br />SCJP 1.4 SCWCD 1.4
Ronald Heukers
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi Pavel,

I found this answer at Dan Chisholms site:

Every class declared within the body of another class is known as a nested class. If the nested class does not have a name, then it is an anonymous class. If the nested class has a name, then it is not anonymous. If the nested class has a name and is declared inside of a method, constructor or any block, then it is a local class. 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. If the nested class has a name and is not declared inside of a method, constructor or any block, then it is a member class. If the class is not nested, then it is a top level class. Please note that this question is more rigorous than those that one might expect to find on the real exam. It has been included here as a convenient place to define some terms that are used to explain the answers to some of the other questions that appear in this mock exam.

see http://www.danchisholm.net/july21/topic/section1/nested1ans.html
and: http://www.danchisholm.net

regards,

Ronald
Ronald Heukers
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
And to make it complex: I believe an a nonstatic nested class is called an inner class.

regards,

Ronald
Ronald Heukers
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Ok, the lat one then about inner classes, and then I stop:

also from

http://www.danchisholm.net/july21/topic/section1/nested1ans.html (question 1)

Every class declared within the body of another class or interface is known as a nested class. If the nested class does not have a name, then it is an anonymous class. If the nested class has a name, then it is not anonymous. If the nested class has a name and is not declared inside of a method, constructor or any block, then it is a member class. If a member class is not static, then it is an inner class. If a class is not nested, then it is a top level class. A nested class that is static is sometimes referred to as a top level class, but that usage of the term is confusing and should be avoided.

regards,

Ronald
Naveen Vooka
Greenhorn

Joined: Oct 13, 2004
Posts: 25
http://www.developer.com/java/other/article.php/3107181
http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html

--------------
Naveen Vooka
www.devsquare.com
DevSquare - Online Application Development
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Local vs Inner