码迷,mamicode.com
首页 > 编程语言 > 详细

java之super关键字

时间:2014-09-30 00:35:41      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   ar   java   strong   sp   

super关键字:

在java中使用super来引用基类的成分。

程序code:

class FatherClass{
    public int value;
    public void f(){
        value = 100;
        System.out.println("FatherClass.value:"+value);
    }
}
class ChildClass extends FatherClass{
    private 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();
    }
}

输出结果:

bubuko.com,布布扣

内存分布:

bubuko.com,布布扣

java之super关键字

标签:style   blog   http   color   使用   ar   java   strong   sp   

原文地址:http://www.cnblogs.com/Gaojiecai/p/4001099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!