在这里插入代码片
@TOC
public class Main {
public static void main(String [] args){
Circle c = new Circle();
Triangle t=new Triangle();
Line l= new Line();
Stuff a=new Stuff();
a.doStuff(c);
a.doStuff(t);
a.doStuff(l);
}}
package com.company;
public class Stuff {
void doStuff(Shape s){
s.draw();
}
}
package com.company;
class Shape{
void draw(){
System.out.println("Shape Drawing");
}
}
package com.company;
class Circle extends Shape {
void draw() {
System.out.println("Shape Circle");
}
}
package com.company;
class Triangle extends Shape{
void draw(){
System.out.println("Shape Three Lines");
}
}
package com.company;
class Line extends Shape{
void draw(){
System.out.println("Shape Lines");
}
}