Meaningless Drivel is fun!*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Method Access" Watch "Method Access" New topic

Method Access

Malk Boy

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 );
marc weber

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
marc weber

Joined: Aug 31, 2004
Posts: 11343

As an aside, note that this version of Car could be streamlined to...
I agree. Here's the link:
subject: Method Access
Similar Threads
object hierarchy problem
Accessing enclosing class method from inner class
UML Relations & Java Implementation