Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about inner classes

 
Pradeep Kumar
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside the MyOuter class you can just use it as MyInner. Outside of MyOuter you have to add the MyOuter.
 
Pradeep Kumar
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic