Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiate a inner class object

 
Waria Ahmed
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm teaching myself about inner classes and am just practicing some code to test what I've learnt. Unfortunately I have got stuck instantiating a object, the following is my code. Would be grateful if anyone could assist me:


I get the error on the line where im trying to create a object. Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Student inner class is not static. Therefore, as all other non-static members (fields, methods), you will need an instance of the enclosing class first:

Either that, or make the class static.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic