aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Instantiating inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Instantiating inner class" Watch "Instantiating inner class" New topic
Author

Instantiating inner class

Latha Kota
Ranch Hand

Joined: Mar 13, 2003
Posts: 35
Hi all,
Can anyone tell me if I can instantiate i.e declare an object of inner class with in the main method. For example:
class Myouter{
int x =7;
public static void main(String []aa){
Myouter.Myinner in = new Myouter.Myinner();
in.inner();
}
class Myinner{
public void inner(){
System.out.println(x);
}
Is this code correct? Thanks in advance.
Latha
Syamsul Hussin
Ranch Hand

Joined: Feb 09, 2003
Posts: 59
because Myinner is not static then you have to instantiate both Mouter and Myinner.
Myouter.Myinner in = new Myouter().Myinner();
[ July 05, 2003: Message edited by: Syamsul Hussin ]

----------------------------------<br />SCJP 1.4
Alex Radomski
Greenhorn

Joined: Apr 24, 2003
Posts: 24
From any static code:
Outer.Inner in = new Outer().new Inner();
Latha Kota
Ranch Hand

Joined: Mar 13, 2003
Posts: 35
Thanks Alex and Syamsul. This will help..
Latha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instantiating inner class