8-inheritance
8-inheritance
ALGORITHM
Step 1: Start
Step 2: Create a class Employee with required variables name, age, phone no, address and
salary.
Step 4: Create a subclass of class Employee named Manager. Include the variable
specialization in manager class.
Step 6: Create another subclass of class Employee named Officer. Include the variable
department in Officer class.
Step 9: Inside the main function read the details of manager from user and create an object
of manager class.
Step 10: Print the manager details by calling the method displayManagerDetails() of
subclass, which invokes the method displayEmployeeDetails() of superclass.
Step 11: Inside the main function, next read the details of officer from user and create an
object of officer class.
Step 12: Print the officer details by calling the method displayOfficerDetails() of subclass,
which invokes the method displayEmployeeDetails() of superclass.
INFERENCE
Understood the concept of inheritance in java by creating a super class and then inheriting
two sub classes from it. Called methods of the subclasses from the main method which
inturn invokes the methods of super class.
PROGRAM
import java.util.Scanner;
class Employee
this.name = name;
this.age = age;
this.phone = phone;
this.address = address;
this.salary = salary;
System.out.println("Name = "+name);
System.out.println("Age = "+age);
System.out.println("Salary = "+salary);
super(name,age,phone,address,salary);
this.specialization = specialization;
displayEmployeeDetails();
String department)
super(name,age,phone,address,salary);
this.department = department;
displayEmployeeDetails();
class EmployeeInheritance
System.out.print("Name:");
String name = sc.nextLine();
System.out.print("Age:");
sc.nextLine();
System.out.print("Phone Number:");
System.out.print("Address:");
System.out.print("Salary:");
sc.nextLine();
System.out.print("Specialization:");
m.displayManagerDetails();
System.out.print("Name:");
System.out.print("Age:");
sc.nextLine();
System.out.print("Phone Number:");
System.out.print("Salary:");
sc.nextLine();
System.out.print("Officer department:");
o.displayOfficerDetails();