1 package oo.day04; 2 //super演示 3 public class SuperDemo { 4 public static void main(String[] args) { 5 Boo o = new Boo(); 6 } 7 } 8 9 class Coo{ 10 int c; 11 Coo(int c){ 12 this.c = c; 13 } 14 } 15 class Doo extends Coo{ 16 Doo(){ 17 super(2); 18 } 19 20 21 /* 22 //如下代码为默认生成的代码,写不写都在那 23 Doo(){ 24 super(); 25 } 26 */ 27 } 28 29 30 31 32 33 34 35 36 37 38 39 40 class Aoo{ 41 int a; 42 Aoo(){ 43 System.out.println("父类构造"); 44 } 45 } 46 class Boo extends Aoo{ 47 int b; 48 Boo(){ 49 //super(); //默认,写不写都在那 50 System.out.println("子类构造"); 51 //super(); //编译错误,必须位于子类构造的第1句 52 } 53 }
时间: 2024-12-25 20:48:39