Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valiveru Mock Exam Question :Question 34.

 
Rosemol Thanjappan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
This question is from another post.There is a discussion for this question
http://www.javaranch.com/ubb/Forum24/HTML/006450.html[/url]
Valiveru Mock Exam Question :
Question 34.
Which of the following are true about inner classes

A. Inner classes can only be instantiated in its outer class
B. Inner classes can be protected or private
C. Anonymous inner class can be both an explicit subclass
and implements an interface.
D. Anonymous inner classes declare and instantiated at the
same place.
E. An inner class can be static only when it's outer class
is static.
F. An instance of an Anonymous inner class can only be
created in it's outer class
They said B and D but I chose F as well.

The following post makes sense.

quote:
--------------------------------------------------------------------------------
Originally posted by Sahir Shah:
1. "An instance of an anonymous or local inner class can only be created within the scope of its declaration "
This statement is true.
2. "An instance of an anonymous or local inner class is accessible only within the scope of its declaration "
This statement is false.
Creating an object is not the same as passing a reference to an object around.
--------------------------------------------------------------------------------

Can any moderators confirm this?
Thanking you Rosemol.
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eventhough u cannot instantiate an anony.in.class outside its outer class, you can get a reference to it anywhere using the superclas it inherits or its outerclass method.
Refer KAM, there is a very good code for getting references.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic