package com.study.oop.demo05;
public class Person {
protected String name = "哆啦A梦";
public Person(){
System.out.println("父类的构造方法");
}
//私有的方法无法被继承
public void print(){
System.out.println("Person");
}
}
//=================================
package com.study.oop.demo05;
public class Student extends Person{
private String name = "樱桃小丸子";
public Student() {
//隐藏代码:调用了父类的无参构造器
super();//调用父类的构造器:必须要在子类的构造器的第一行
System.out.println("子类的无参构造器");
}
public void print(){
System.out.println("Student");
}
public void test1(){
print();//Student
this.print();//Student
super.print();//Person
}
public void test(String name){
System.out.println(name);//super
System.out.println(this.name);//樱桃小丸子
System.out.println(super.name);//哆啦A梦
}
}
//=================================
package com.study.oop;
import com.study.oop.demo05.Student;
public class Application {
public static void main(String[] args) {
Student student = new Student();
// student.test("super");
// student.test1();
}
}