[Java]Points in Invoking Constructors in Super Class - Java Programming Language
来源:互联网 发布:c语言学会了有什么用 编辑:程序博客网 时间:2024/04/30 03:52
• To invoke a parent constructor, you must place a call to super in the first line of the constructor.
• You can call a specific parent constructor by the arguments that you use in the call to super.
• If no this or super call is used in a constructor, then the compiler adds an implicit call to super() that calls the parent no argument constructor (which could be the default constructor).
If the parent class defines constructors, but does not provide a no-argument constructor, then a compiler error message is issued.
Now you can see what happened here.
• You can call a specific parent constructor by the arguments that you use in the call to super.
• If no this or super call is used in a constructor, then the compiler adds an implicit call to super() that calls the parent no argument constructor (which could be the default constructor).
If the parent class defines constructors, but does not provide a no-argument constructor, then a compiler error message is issued.
Supposed that there is a super class called Employee
For example:
public class Manager extends Employee {private String department;public Manager(String name, double salary, String dept) {super(name, salary);department = dept;}public Manager(String name, String dept) {super(name);department = dept;}public Manager(String dept) { // This code fails: no super()department = dept;}//more Manager code...}
Now you can see what happened here.
- [Java]Points in Invoking Constructors in Super Class - Java Programming Language
- Generics in the Java Programming Language Java
- [Java]the Keywords in Java Programming Language
- 《Generics in the Java Programming Language》译文
- 转:Password Masking in the Java Programming Language
- Thinking in Java(6)-private constructors
- Declarative Programming in Java
- Programming in Java: Multi-threads and interface vs abstract class
- implement, extends, super in Java
- Programming in the Ruby language
- BST_Iterative class in Java
- Static class in Java
- In class programming 2
- In class programming 1
- Thinking in Java(4)-Calling constructor from constructors
- Thinking in Java(8)-Behavior of Polymorphic methods inside constructors
- Proficiency in Java swing programming
- Killer Game Programming in Java
- Gabor变换
- 【信息图】“10亿美元级”初创企业
- awk命令详解
- Qt创建对话框
- LeetCode 3 - Longest Substring Without Repeating Characters
- [Java]Points in Invoking Constructors in Super Class - Java Programming Language
- sed命令详解
- 将SVN与BUG跟踪管理集成
- jquery 查询
- 网络流 学习小记2
- 虚拟机通过iso镜像安装win7时出现A:\GHOSTERR.TXT的解决办法
- LeetCode 4 - Median of Two Sorted Arrays
- Zend Studio 10正式版注册破解
- HDU3110 Crystal Ball Factory