面向对象第二章(引用类型数组、继承)

1.引用类型数组: 1)Student[] stus = new Student[3]; //创建Student数组对象 stus[0] = new Student("zhangsan",25,"LF"); //创建Student对象 stus[1] = new Student("lisi",26,"JMS"); stus[2] = new Student("wangwu",28,"SD"); System.out.println(stus[0].address); 2)Student[] stus = new Student[]{ new Student("zhangsan",25,"LF"), new Student("lisi",26,"JMS"), new Student("wangwu",28,"SD") }; 3)int[][] arr = new int[3][];-----------数组的数组 arr[0] = new int[2]; arr[1] = new int[3]; arr[2] = new int[2]; arr[1][0] = 100; 4)int[][] arr = new int[3][4];----------数组的数组 for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j] = (int)(Math.random()*100); } } 2.继承: 1)作用:代码复用 2)通过extends来实现继承 3)超类/父类:所有派生类所共有的属性和行为 派生类/子类:派生类所特有的属性的行为 4)派生类继承超类后,派生类具有:派生类的+超类的 5)一个超类可以有多个派生类 一个派生类只能有一个超类-------单一继承 6)继承具有传递性 7)java规定:构造派生类之前必须先构造超类 在派生类的构造方法中若没有调用超类的构造方法 ------则默认super()调用超类的无参构造方法 在派生类的构造方法中若调用了超类的构造方法 ------则不再默认提供 注意:super()调用超类构造必须位于派生类构造的第一行 3.super:指代当前对象的超类对象 super的用法: 1)super.成员变量名------------访问超类的成员变量 2)super.方法名()--------------调用超类的方法-------明天讲 3)super()---------------------调用超类的构造方法

原文地址:https://www.cnblogs.com/ahaijava/p/9965889.html