日期:2014-05-20 浏览次数:20838 次
class Shape{ void style(){ } } class Circle extends Shape{ void style(){ System.out.println("Circle's Style"); } } class Square extends Shape{ void style(){ System.out.println("Square's Style"); } } class Person{ private String name; Person(String name,Shape i){ i.style(); } } public class TestShape { public static void main(String[] args) { Circle c = new Circle(); Square s = new Square(); Person p1 = new Person("name1",c); Person p2 = new Person("name2",s); } }
class Shape{ void style(){ } } class Circle extends Shape{ void style(){ System.out.println("Circle's Style"); } } class Square extends Shape{ void style(){ System.out.println("Square's Style"); } } public class TestShape { public static void main(String[] args) { Shape sh; Circle c = new Circle(); Square s = new Square(); sh=c; sh.style(); sh=s; sh.style(); } }