wood burning stoves 2.0*
The moose likes Java in General and the fly likes Method Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method Access" Watch "Method Access" New topic
Author

Method Access

Malk Boy
Greenhorn

Joined: Feb 17, 2005
Posts: 1
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

Joined: Aug 31, 2004
Posts: 11343

Just connect the dots: CarRef.EngineRef.method();


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

As an aside, note that this version of Car could be streamlined to...
 
Consider Paul's rocket mass heater.
 
subject: Method Access
 
Similar Threads
DOUBT on DOWNCASTING
object hierarchy problem
Accessing enclosing class method from inner class
UML Relations & Java Implementation
super.super