1 package day1.yppah02; 2 3 /* 4 2.8. Java中继承的注意事项 5 6 1. Java中类只支持单继承,不支持多继承 7 错误范例:class A extends B, C { } 8 2. Java中类支持多层继承 9 正确范例:calss B extends A { } 10 calss C extends B { } 11 */ 12 13 /*public class Son extends Father, Mother{ //error 14 15 }*/ 16 17 public class Son extends Father{ 18 19 }
1 package day1.yppah02; 2 3 public class Mother { 4 5 public void dance(){ 6 System.out.println("妈妈爱跳舞"); 7 } 8 9 }
1 package day1.yppah02; 2 3 public class Father extends Granddad{ 4 5 public void smoke(){ 6 System.out.println("爸爸爱抽烟"); 7 } 8 9 }
1 package day1.yppah02; 2 3 public class Granddad { 4 5 public void drink(){ 6 System.out.println("爷爷爱喝酒"); 7 } 8 9 }