J2SE - super
在Java中:
this 是对当前对象的引用
super是对当前对象的父类对象的引用
看这个例子:
- class FatherClass
 - {
 - public int value;
 - public void f()
 - {
 - value = 100 ;
 - System.out.println("FatherClass.value" + value);
 - }
 - }
 - class ChildClass extends FatherClass
 - {
 - public int value;
 - public void f()
 - {
 - super.f();
 - value = 200 ;
 - System.out.println("ChildClass.value" + value);
 - System.out.println(value);
 - System.out.println(super.value);
 - }
 - }
 - Public class TestInherit
 - {
 - public static void main(String[] args)
 - {
 - ChildClass cc = new ChildClass();
 - cc.f();
 - }
 - }
 
内存分析:
运行完
- ChildClass cc = new ChildClass();
 
因为ChildClass继承了FatherClass,则ChildClass继承了FatherClass的所有成员变量和方法,所以ChildClass的内存中还有一个FatherClass。
当new出一个对象时,内存中就会有一个this引用,this引用指向对象自身,如果此对象继承父类,则还有一个super,super就指向父类对象
并不难懂的小知识,对不对! Over!
                    
                
                
            
        
浙公网安备 33010602011771号