多态练习
程序员文章站
2022-05-30 08:58:11
1 public class Fu { 2 int num = 3; 3 void show() { 4 System.out.println("F1"); 5 } 6 static void method() { 7 System.out.println("F2"); 8 } 9 } 1 publ... ......
1 public class Fu { 2 int num = 3; 3 void show() { 4 System.out.println("F1"); 5 } 6 static void method() { 7 System.out.println("F2"); 8 } 9 }
1 public class Zi extends Fu{ 2 int sum = 4; 3 4 void show() { 5 System.out.println("Z1"); 6 } 7 8 static void method() { 9 System.out.println("Z2"); 10 } 11 }
1 public class DouTaiDemo { 2 public static void main(String[] args) { 3 Fu f = new Zi(); 4 System.out.println(f.num); 5 f.show(); 6 f.method(); 7 } 8 9 }