File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Instantiating inner class" Watch "Instantiating inner class" New topic

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();
class Myinner{
public void inner(){
Is this code correct? Thanks in advance.
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

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..
subject: Instantiating inner class
jQuery in Action, 3rd edition