Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling inner classes?

 
Rob Brew
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm following the oracle training guide as best i can, trying to play with inner classes though and i'm lost. I'm having problems at line 47. how do i call and use innner classes?

Thanks for all your help guys, it means a lot.

vehicle.java


taxi.java


cab.java

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Brew wrote:... I'm having problems at line 47. how do i call and use innner classes? ...

I think your problem is actually at line 64.

An instance of an inner class (Speedo) always needs to be associated with an instance of the enclosing class (taxi). This means you need an instance of taxi before you can create an instance of Speedo. So instead of just...

...create a new instance of taxi first, then use that instance to create a new Speedo...


Edit: Note that if you already have an instance of the enclosing class, then you could simply use that. For example...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic