大家帮忙看看我写的这个算多态么
又看了下多态对多态好像有了些感觉 所以写个程序 大家看下 这应该算是多态吧? 但是好像 对于多态的特点好像不是能很好的体现,大家说下应该如何完善这个代码段才能更加体现多态????
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(); }}