1. 程式人生 > >RTTI實現原理(多型的原理)

RTTI實現原理(多型的原理)

Human anotherPerson = new Woman(); Class c2 = anotherPerson.getClass(); System.out.println(c2.getName());
} }
class Human {
/** * accessor */ public int getHeight() { return this.height; } /** * mutator */ public void
growHeight(int h) { this.height = this.height + h; } private int height; } class Woman extends Human { /** * new method */ public Human giveBirth() { System.out.println("Give birth"); return (new Human()); } }