JAVA Inheritance With Concept and Examples / Output

PROGRAM STATEMENT

Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class by writing three subclasses namely Teaching (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

CONCEPT

[alert-announce]Here in this given problem we shall use inheritance for extending Staff class into Teaching, Technical and Contract 3 subclasses using extends keyword. Each class is having the variables as given in the bracket. We will import the util package Scanner class to read 3 objects of each class. Create a constructor of Staff class to initialize StaffId, Name, Phone, Salary. And one display functions into the Staff class to display the entered values. All the data members of Staff will be inherited in Teaching, Technical and Contract using the super keyword that calls the superclass constructor to the base class. Other additional data members of the subclasses would be initialized using their own constructor. Also along with their own constructors, all 3 subclasses will have their own display method that invokes display method of super class Staff. Now in main() method using Scanner class we will read the values accordingly. To display these values we will create an array of object of size 3 for each subclass Teaching, Technical and Contract. Using this array of objects we will display the values entered previously by invoking display method of each subclass. Below is the program that demonstrates the same.[/alert-announce]

 

EXAMPLE INHERITANCE IN JAVA (SUPER CLASS / SUBCLASS) PROGRAM

/** Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend
this class by writing three subclasses namely Teaching (domain, publications),
Technical (skills), and Contract (period). Write a Java program to read and display at
least 3 staff objects of all three categories.*/

OUTPUT

[alert-success]

JAVA Inheritance With Concept and Examples

Output of JAVA Inheritance

[/alert-success]

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is the owner of RabinsXP who is constantly working for increasing Internet of Things (IoT) in Nepal. He also builds android apps and crafts beautiful websites. He is also working with various social services. The main aim of Lamichhane is to digitally empower the citizens of Nepal and make the world spiritually sound better both in terms of technology and personal development.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: