interface Shape{ void draw(); } class A implements Shape{ public void draw(){System.out.println("A");} } class B implements Shape{ public void draw(){System.out.println("B");} } public class TestShpe{ Shape [] shape; shape[0] = new A(); shape[1] = new B(); public static void main(String [] args){ for(int i=0;i<shape.length;i++){ shape[i].draw(); } } }
interface Shape{ pulbic void draw(); } class 圆形 implement Shape { public void draw(){ system.out.println(" 画圆"); } } class 正方形 implement Shape { public void draw() { system.out.println(" 画正方形"); } } class main { public static void main(string [] args) Shape yuan = new 圆形(); Shape zheng = new 正方形(); yuan.draw(); zheng.draw(); //他们虽然调用同一个方法draw.但行为各自不同。一个画圆,一个画正方。 } 别忘了给分呀!
void draw();
}
class A implements Shape{
public void draw(){System.out.println("A");}
}
class B implements Shape{
public void draw(){System.out.println("B");}
}
public class TestShpe{
Shape [] shape;
shape[0] = new A();
shape[1] = new B();
public static void main(String [] args){
for(int i=0;i<shape.length;i++){
shape[i].draw();
}
}
}
pulbic void draw();
}
class 圆形 implement Shape
{
public void draw(){
system.out.println(" 画圆");
}
}
class 正方形 implement Shape
{
public void draw()
{
system.out.println(" 画正方形");
}
}
class main
{
public static void main(string [] args)
Shape yuan = new 圆形();
Shape zheng = new 正方形();
yuan.draw();
zheng.draw();
//他们虽然调用同一个方法draw.但行为各自不同。一个画圆,一个画正方。
}
别忘了给分呀!