直接上代码:class Father {
private String aaa = "我来测试";
public Father() {
System.out.println("father this.getClass():"+this.getClass());//表示当前运行时的对象的class
System.out.println("father this.hashCode(:"+this.hashCode());
System.out.println("father this:"+this);
System.out.println("father this.aaa:"+this.aaa);
this.test();
}
private void test(){
System.out.println("我是私有化的方法");
}
public int dowork() {
System.out.println("我要去工作了");
return 1;
}
}
class Son extends Father {
private String bbb = "我来测试1";
public Son() {
System.out.println("son super.getClass():"+super.getClass());//表示父类运行时的class
System.out.println("son this.hashCode():"+this.hashCode());
System.out.println("son this:"+this);
}
}
public class FatherDemo{
public static void main(String[] args) {
Father f = new Son();
}
}
运行结果是这样的:
father this.getClass():class xiaomage.Son
father this.hashCode(:581882789
father this:xiaomage.Son@22aed3a5
father this.aaa:我来测试
我是私有化的方法
son super.getClass():class xiaomage.Son
son this.hashCode():581882789
son this:xiaomage.Son@22aed3a5