This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Class

 
santhoshK babu
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody,
The following code catches the following error...

Can any one say why it is not possible to create object for an inner class..

class j{
int p=58;
class k{
int l=87;
}
public static void main(String argsssss[]){
j obj1=new j();
k obj2=new k();
}

}

/*Output
F:\san>javac j.java
j.java:8: non-static variable this cannot be referenced from a static context
k obj2=new k();
^
1 error
*/

Thanks in advance..
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The inner class is a member of the class definition, and cannot be accessed from a static context.

In the main method you need to create an instance of the class first, and then use that to create the instance of the inner class.
 
wise owen
Ranch Hand
Posts: 2023
 
Ramamoorthy Periasamy
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic