super()与this()的区别
This():当前类的对象,super父类对象。
Super():在子类访问父类的成员和行为,必须受类继承规则的约束
而this他代表当前对象,当然所有的资源都可以访问.
在构造函数中,如果第一行没有写super(),编译器会自动插入.但是如果父类没有不带参数的构造函数,或这个函数被私有化了(用private修饰).此时你必须加入对父类的实例化构造.而this就没有这个要求,因为它本身就进行实例化的构造.
而在方法中super和this使用的方法就差不多了.只不过super 要考虑是否能访问其父类的资源.
Super():在子类访问父类的成员和行为,必须受类继承规则的约束
而this他代表当前对象,当然所有的资源都可以访问.
在构造函数中,如果第一行没有写super(),编译器会自动插入.但是如果父类没有不带参数的构造函数,或这个函数被私有化了(用private修饰).此时你必须加入对父类的实例化构造.而this就没有这个要求,因为它本身就进行实例化的构造.
而在方法中super和this使用的方法就差不多了.只不过super 要考虑是否能访问其父类的资源.
【super()与this()的区别】相关文章
2. super关键字的用法
3. What\'s the difference between Debug and Trace class? (Debug类与Trace类有什么区别)
5. Does C# support multiple inheritance? (C#支持多重继承吗)
6. 说说在weblogic中开发消息Bean时的persistent与non-persisten的差别
7. 软件测试LoadRunner面试题:How did you find web server related issues?
8. 软件测试LoadRunner面试题:How do you identify the performance bottlenecks
9. 软件测试LoadRunner面试题:What is think time? How do you change the threshold?
10. 软件测试LoadRunner面试题:If web server, database and Network are all fine where could be the problem?
本文来源:https://www.mianshiwenti.com/a12324.html
进入下载页面
﹝super()与this()的区别﹞相关内容
- Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型
- 软件测试LoadRunner面试题:What is Ramp up? How do you set this
- 软件测试LoadRunner面试题:If you want to stop the execution of your script on error, how do you do that?
- 软件测试LoadRunner面试题:How did you plan the Load? What are the Criteria?
- Java中有几种方法可以实现一个线程?用什么关键字修饰同步方法?stop()和suspend()方法为何不推荐使用?
- 第二层交换机和路由器的区别?第三层交换机和路由器的区别?
- How to detect and cleanup pending transactions in Oracle
- What\'s the difference between an interface and abstract class? (接口与抽象类有什么区别)
- 软件测试LoadRunner面试题:What is the difference between Overlay graph and Correlate graph?
- Overload和Override的区别