| Author |
about inner classes
|
Pradeep Kumar
Ranch Hand
Joined: Sep 11, 2007
Posts: 77
|
|
Hi, I was just working on inner classes and want to know how to instantioate an inner class, In the book its given as MyOuter.MyInner innerObj = new MyOuter().new MyInner(); But the way i instantiated is MyInner innerObject = new MyOuter().new Inner(); Are the two declarations have the same effect or is there a diiference in them. Plese reply asap. Below is the code snippet. public class MyOuter { private int x=5; public class MyInner{ public void justPrint() { System.out.println("The value of i is "+x); } } public static void main(String args[]) { MyInner object = new MyOuter().new MyInner(); object.justPrint(); } }
|
SCJP 1.6
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Inside the MyOuter class you can just use it as MyInner. Outside of MyOuter you have to add the MyOuter.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Pradeep Kumar
Ranch Hand
Joined: Sep 11, 2007
Posts: 77
|
|
|
thanks
|
 |
 |
|
|
subject: about inner classes
|
|
|