270 likes | 374 Vues
This article explores the concept of default constructors in Java, particularly focusing on their role in subclass constructors. A default constructor initializes an instance with default values, like an `Employee` class where `number` is set to 0 and `name` is an empty string. When subclassing, it's crucial to call the default constructor of the superclass as the first statement. We'll demonstrate how to utilize `super` to access superclass methods and attributes, such as `super.getName()` and `super.accNumber()`, ensuring a smooth inheritance process.
E N D
Note: Add a default constructor public Employee (){ number =0; name=“”;} Note: The default constructor is called as the first statement in the subclass constructor
in branNA: String in bankNA: String
Note: supercan be used to access the supers class methods and attributes. For example: super.getName(); super.accNumber;