1.this关键字
package cn.tedu;
public class ReviewThis {
public static void main(String[] args) {
cat c = new cat();
c.test();
}
}
class cat{
public cat(){
this(8);
System.out.println("无参构造");
}
public cat(int num) {
this.num = num;
System.out.println("含参构造");
}
int num ;
public void test(){
int num = 10;
System.out.println(num);
System.out.println(this.num);
}
}
2.super关键字
package cn.tedu;
public class ReviewSuper {
public static void main(String[] args) {
father father = new father("r");
father.test01();
son son = new son();
son.test02();
}
}
class father{
String s = "父类的成员变量s";
public father() {
System.out.println("父类的无参构造");
}
public father(String s) {
this.s = s;
System.out.println("父类的含参构造");
}
public void test01(){
String s = "父类的局部变量s";
System.out.println(s);
System.out.println(this.s);
}
}
class son extends father{
String s = "子类的成员变量s";
public son() {
super("t");
System.out.println("子类的无参构造");
}
public void test02(){
String s = "子类的局部变量s";
System.out.println(s);
System.out.println(this.s);
System.out.println(super.s);
}
}



