File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Inner Class" Watch "Inner Class" New topic
Author

Inner Class

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Which of the following are valid to be placed
at xxxxxxx ?
a) new Inner()
b) new Outer().new Inner()
c) this.Inner()

class Outer {
class Inner {
public void method(String i) {
System.out.println("eeeee");
}
}
public static void main(String [] args) {
Inner i = xxxxxxxxx
}
}
pleasw explain
YARRAM SREENIVASA REDDY
Greenhorn

Joined: Aug 18, 2000
Posts: 1
In the above question you send the correct answer is
new Outer().new Inner()
The first one you cannot use because you need the instance of enclosing class when you want to create the instance of inner class so you need it . One Imp thing is that when your inner class is given static you can directly instantiate the inner class in static methods of enclosing class.
The last one is directly you can throw it out because u cannot use this keyword in static methods.
Please reply back me your feelings whether you satisfied or not.
I am the new member in this group please send my reference to all.
My mail i.d is sreddyy@yahoo.com
------------------


<BR>
Micheal Zhao
Greenhorn

Joined: Aug 28, 2000
Posts: 4


new Outer().new Inner()
I think the right question is :
Outer.Inner i = new Outer().new Inner().
if use Inner i , it will be a compiler error.
Micheal
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi,
the correct answer is
new Outer().new Inner();
regards
deekasha

 
 
subject: Inner Class
 
Threads others viewed
Inner Class
Inner classes
Inner Class - Initialization Sequence
use of Outer.this
Inner Class
IntelliJ Java IDE