Forums Register Login

Local vs Inner

+Pie Number of slices to send: Send
Can anyone explain to me what's the difference between local and inner classes? I was unable to find an explanation.
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
And to make it complex: I believe an a nonstatic nested class is called an inner class.

regards,

Ronald
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 909 times.
Similar Threads
Method Local inner class
Inner class
method-local inner class object cannot use the local variables
Outer class instance
regd local inner class (method level)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:27:53.