class Shape { void draw() { System.out.println("Shape.draw()"); } } class Circle extends Shape{ void draw() { System.out.println("Circle.draw()"); } } class Line extends Shape{ void draw() { System.out.println("Line.draw()"); } } public class Test { public static void main(String[] args) { // TODO 自动生成方法存根 Shape s = new Circle(); s.draw();//这里的调用就是多态,虽然s是Shape,但调用draw()的时候能够正 //确调用Circle的draw(),是多态使程序能正确调用 } }
void draw() {
System.out.println("Shape.draw()");
}
}
class Circle extends Shape{
void draw() {
System.out.println("Circle.draw()");
}
}
class Line extends Shape{
void draw() {
System.out.println("Line.draw()");
}
}
public class Test { public static void main(String[] args) {
// TODO 自动生成方法存根
Shape s = new Circle();
s.draw();//这里的调用就是多态,虽然s是Shape,但调用draw()的时候能够正 //确调用Circle的draw(),是多态使程序能正确调用
}
}
老子 a=new 小子