this & super
来源:互联网 发布:java后端接口开发技术 编辑:程序博客网 时间:2024/05/21 14:50
this 的使用:
this 是 Java 的一个关键字,表示每个实例对象指向自己的引用,如图所示;其可以出现在实例方法和构造方法中,不能出现在由 static 修饰的类方法(静态方法)中。
<1>在实例方法中使用this,即 this.本类实例变量名、this.本类实例方法名。
<2>区分实例变量和局部变量
<3>返回实例对象本身的引用,即 return this;
<4>使用 this 调用类的其他构造方法:
使用 this(parameter list); 来调用该类的其他构造方法,具体调用哪个构造方法根据 this 的参数类型确定,即由this(parameter list);确定。
super 的使用:
super 是 Java 的一个关键字, 表示子类实例对象中指向父类的引用,如图所示;和this一样,其可以出现在实例方法和构造方法中,不能出现在由 static 修饰的类方法(静态方法)中。
<1>可以使用 super 实现子类调用父类被覆盖的方法和实例变量, 即 super.父类实例变量名、super.父类实例方法名。
<2>使用 super 调用父类中的构造方法
使用 super(parameter list); 来调用父类的构造方法,具体调用哪个构造方法根据 super 的参数类型确定,即由super(parameter list);确定。
- this super
- this super
- this & super
- this & super
- this super
- this super
- this super
- super & this
- this&super
- this super
- this & super
- this super
- this,super
- this super
- super|this
- super() this() super this 与构造函数
- super与 this
- super 和 this
- 密钥管理
- tomcat部署服务配置备忘
- 命名空间和std用法
- vc2005编译出来的程序实现绿色版,即无须安装运行库
- C++控制台程序获取本机IP地址
- this & super
- C++查漏补缺读书笔记一 友元(friend)
- Qt系统托盘程序
- 【算法】康托展开
- ERROR: ORA-12560: TNS: 协议适配器错误--解决办法
- Genesis-3D 入门教程—23.动画融合
- 【cocos2d-x IOS游戏开发-捕鱼达人18】积分板实现
- sku算法[http://ued.taobao.org/blog/?p=5894]
- 反射,通过类名(字符串)获取类