1 / 27

Understanding Default Constructors in Java Subclassing

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.

warner
Télécharger la présentation

Understanding Default Constructors in Java Subclassing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Note: Add a default constructor public Employee (){ number =0; name=“”;} Note: The default constructor is called as the first statement in the subclass constructor

  2. Include this part in the subclass constructor

  3. in branNA: String in bankNA: String

  4. Note: supercan be used to access the supers class methods and attributes. For example: super.getName(); super.accNumber;

More Related