Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method Access

 
Malk Boy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is how do I access the methods of the engine class in the control class when I pass an object car to control.

Thanks for any help

public class Car
{
Engine e;

public car ()
{
e = new Engine();
}

public static void main ( String[] args )
{
Car c = new Car();
Control ctrl = new Control ( c );
ctrl.runSystem();
}
}
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just connect the dots: CarRef.EngineRef.method();
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, note that this version of Car could be streamlined to...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic