13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

92Chapter 3An Experienced Programmer’s Introducti<strong>on</strong> to JavaExample 3.28 The Pers<strong>on</strong> classclassPers<strong>on</strong>{String name;Address addr;}publicPers<strong>on</strong>(String name, Address addr){this.name = name;this.addr = addr;} // c<strong>on</strong>structor// ... lots more code is herepublic String getName(){return name;}Example 3.29 An example use of polymorphism//...Sample labwork = new Sample(petridish);Employee tech = new Employee(newguy, 27);Identifiable stuff;//...if (mode) {stuff = labwork;} else {stuff = tech;}id = stuff.getID();The key point here is when the call is made to getID(). The compilercan’t know at compile time which object will be referred to by stuff, so itdoesn’t know whose getID() method will be called. But d<strong>on</strong>’t worry—it works

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

Saved successfully!

Ooh no, something went wrong!