13.07.2015 Views

4. Object Structures, Aliasing, and Encapsulation

4. Object Structures, Aliasing, and Encapsulation

4. Object Structures, Aliasing, and Encapsulation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}rep Engine getEngine() { return engine; }void setEngine( rep Engine e){ engine=e; }void go () {if(driver!=null) engine.start();}class Main {void main() {Driver bob = new Driver(); // root ownerCar car = new Car(); // root ownercar.driver = bob;car.go();car.engine.stop();car.getEngine().stop();// fails// fails}}rep Engine e = new rep Engine();car.setEngine(e);// fails13.05.13© A. Poetzsch-Heffter, TU Kaiserslautern44

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!