super
作者:互联网
super ``` super注意点: 1.super调用父类的构造方法,必须在构造器方法的第一个 2.super必须只能出现在子类的方法或者构造器中! 3.super和this不能同时调用构造方法 vs this: 代表的对象不同: this:本身调用着这个对象 super:代表父类对象的应用 前提 this:没有继承也可以使用 super:只能在继承条件才可以使用 构造方法 this():本类的构造 super():父类的构造 ``` ``` package opp; import opp.Dome05.Person; import opp.Dome05.Student; public class Application01 { public static void main(String[] args) { Student student = new Student(); //student.test("王刚"); //student.test2(); } }xxxxxxxxxx package opp.Dome05;//说有的类都会默认直接或者间接的继承Object//人 父类public class Person { public Person() { System.out.println("person"); } public Person(String name) { this.name = name; } protected String name ="xyc"; //私有的东西无法被继承 public void print(){ System.out.println("Person"); }} ``` ``` package opp; import opp.Dome05.Person; import opp.Dome05.Student; public class Application01 { public static void main(String[] args) { Student student = new Student(); //student.test("王刚"); //student.test2(); } }xxxxxxxxxx package opp.Dome05;//说有的类都会默认直接或者间接的继承Object//人 父类public class Person { public Person() { System.out.println("person"); } public Person(String name) { this.name = name; } protected String name ="xyc"; //私有的东西无法被继承 public void print(){ System.out.println("Person"); }} ```
标签:opp,name,Person,Student,super,public 来源: https://www.cnblogs.com/java5745/p/15011124.html