package test02;
//权限修饰符在继承中注意事项
import test01.Order;
public class subOrder extends Order {
public void test() {
protectedData=1;
publicData=2;
protectedMethod();
publicMethod();
//同一个包的其它类中不能调用Order的私有属性和方法
//不同包的子类中,不能调用Order类中的private和default属性和方法
//不同包的普通类之间只能调用public的属性和方法
// privateData=3;
// defaultData=4;
// privateMethod();
// defaultMethod();
}
}
package superTest;
/**
* super关键字的使用
* 1.super可以理解为:父类的
* 2.super可以用来调用属性、方法、构造器
* 3.super的使用:
* 3.1 我们可以在子类的方法或构造器中,通过使用super.属性或super.方法的方式显式调用
* 父类中的声明的属性。通常情况下省略"super"
* 3.2 特殊情况:当子类定义了和父类同名的属性时,当我们想调用父类的属性时,super不能省略
* 3.3 特殊情况:当子类重写了父类中的方法,在子类中调用父类中被重写的方法时,要显式给出super
* 4.super调用构造器
* 4.1 我们可以在子类的构造器中显式地使用"super(形参列表)"的方式,调用父类中声明的指定
* 构造器
* 4.2 super(形参列表)的使用必须在子类构造器的首行
* 4.3 this(形参列表)和super(形参列表)在类的构造器中只能二选一
* 4.4 当类的构造器首行没有显式地使用this(形参列表)和super(形参列表),默认是super()
* 4.5 在类的多个构造器中,至少有一个类的构造器使用了super(形参列表)结构,调用父类的构造器
* @author tongy
*
*/
public class SuperTest {
public static void main(String[] args) {
Student student=new Student();
student.show();
student.study();
System.out.println("-----------------");
Student student2=new Student();
student2.age=23;
}
}