super()和this()方法
来源:互联网 发布:javascript的作用 编辑:程序博客网 时间:2024/04/30 16:03
super():表示调用父类的构造方法
this():表示条用本类的其他构造方法
用法:
1,用在类的构造方法中;
2,必须写在构造方法的第一行;(因为类必须构造完成后才能进行其他操作)
3,不可以在一个构造方法中同时使用;(如果同时使用的话,this()会调用父类的构造方法,和super()冲突)
package java.superThis;public class TestSuper {public TestSuper() {System.out.println("super null cons");}public TestSuper(String a) {System.out.println("super name cons");}}
package java.superThis;public class TestThis extends TestSuper{public TestThis() {this("a", "b");System.out.println("this null cons");}public TestThis(String a) {super(a);System.out.println("this name cons");}public TestThis(String a, String b) {super();System.out.println("this name cons");}}
阅读全文
0 0
- super()和this()方法
- 构造方法,super,this
- super 和 this
- this 和 super
- this和super
- 关于this 和 super
- this和super关键字
- this 和 super关键字
- this 和 super
- super和this
- super()和this()区别?
- super和this关键字
- this和super
- this、super和final
- this和super
- super和this。
- this和super
- this 和 super用法
- 互不侵犯king
- 常用算法
- opencv 编译库依赖问题
- 复盘_8月(第1周工作复盘)
- python 获取和编辑windows系统环境变量
- super()和this()方法
- MapReduce 开发问题和解决方法汇总
- 从1到n整数中1出现的次数
- js中关于字符串转日期的小问题集合
- leetcode--Gray Code
- JAVA8自定义Lambda表达式的常见使用方法
- 定义字符串的左旋转操作:把字符串前面的若干个字符移动到字符串的尾部。 * 如把字符串abcdef左旋转2位得到字符串cdefab。
- react native ScrollView自动滑动到顶部
- java反射机制