代表的对象不同
this: 本身调用 用这个对象
super: 代表父类对象的应用
前提
this: 没有继承也可以使用
super: 只能在继承条件才可以使用
构造方法
this() 本类的构造
super(); 父类的构造
package com.etc.ood.demo1; public class Person { protected String name = "chen"; public Person() { System.out.println("person无参执行了"); } public void print() { System.out.println("person"); } } package com.etc.ood.demo1; public class Student extends Person{ String name = "stuchen"; public Student() { //隐藏代码: 调用了父类的无参构造 super(); System.out.println("studet无参执行了"); } public void print(){ System.out.println("Student"); } public void test1(){ this.print(); super.print(); } public void test(){ System.out.println(name); System.out.println(this.name); System.out.println(super.name); } } package com.etc.ood.demo1; public class Application { public static void main(String[] args) { Student student = new Student(); // student.test(); student.test1(); } }