RTTI實現原理(多型的原理)
阿新 • • 發佈:2019-01-25
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());
}
}
} } class Human {
/** * accessor */ public int getHeight() { return this.height; } /** * mutator */ public void