• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Innerclass Qn

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one is from JTest
Which statement is true about a non-static inner class?
A. It must implement an interface.
B. It is accessible from any other class.
C. It can only be instantiated in the enclosing class.
D. It must be final if it is declared in a method scope.
E. It can access private instance variables in the
enclosing object.
Ans given is E.
My ans B,D,E
I think B is partially true.
inner class can be accessed from outer class if it is not declared private.(and ofcourse we have to create the instance of enclosing class).
c)inner class inside method scope is implicitly final
We cannot subclass an inner class declared inside a method scope.
Please correct me if I am wrong.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mani,I
Innerclasses declard with in the method scope can be
declared abstract or final. When I heard this, even
I got .
I really don't know how this feature can be used,
but it helps to remember this for the exam
Hope this helps.

Ajith
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I found one of the most interesting inner class discussion on this forum.
Check this out
www.javaranch.com/ubb/Forum24/HTML/001159.html
Hope this helps
Ajay
 
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mani,
B is obviously wrong. You should pay attention the phrase "any class". Surely an inner class is not accessed from any class, its accessibility outside the class in which it is defined will depend upon the its access modifiers and those of its encompassing class. And for a local inner class (one declared inside a method), you should know that it can never be declared as private,static,public or protected.And being local, you know that it exists only for as long as the method that contains exists. So it can only be accessed in the class that it is contained.
D is also wrong. You are right to say that local inner classes are implicitly final. Again pay attention to the phrase "must ". It is not a must that they be declared final, but they may be declared final, redundant though.
I think such phrases are what we ought to watch out for when deciding which answer is correct.

What do you think?
 
Mani
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I have to study little bit of English Grammer also for the Sun Certification Exam.

 
Always look on the bright side of life. At least this ad is really tiny:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic