Note: ===== ==> Multiple Inheritance does not support in java at class level but we can implement with interface. ==> Hybrid Inheritance also not possible to implement at class level. Hierarchical Inheritance: ========================= The parent class can be inherit to two or more child classes is called as "Hierarchical Inheritance". Syntax: ======= class Parent{ } class Child1 extends Parent{ } class Child2 extends Parent{ } package AIT.IO.Java; class Employee{ private String name; private int eid; private String type; // full time or contract private double salary; public Employee(String name, int eid, String type, double salary) { super(); this.name = name; this.eid = eid; this.type = type; this.salary = salary; } public void display() { System.out.println("Employee ID = "+eid); System.out.println("Employee Name = "+name); System.out.println("Type of EMployement = "+type); System.out.println("Employee Salary = "+salary); } } class FullTimeEmployee extends Employee{ public FullTimeEmployee(String name, int eid, String type, double salary) { super(name, eid, type, salary); } public void display() { System.out.println("The FullTime EMployee Details:"); super.display(); } public void hike() { System.out.println("Hike for Full time employee is 30%"); } } class ContractEmployee extends Employee{ public ContractEmployee(String name, int eid, String type, double salary) { super(name, eid, type, salary); } public void display() { System.out.println("The Contract Employee Details are = "); super.display(); } } public class MainClass { public static void main(String[] args) { ContractEmployee ct = new ContractEmployee("Giri",1010,"Contractual",56000.0); ct.display(); // ct.hike(); FullTimeEmployee ft = new FullTimeEmployee("Rajath",1011,"FullTime",54000.0); ft.display(); ft.hike(); } } ============================================================= /* * WAP TO IMPLEMENT THE FOLLOWING: * 1) CREATE THE CLASS WITH THE NAME VEHICLE AND DEFINE THE ATTRIBUTES: SPEED AND FUELTYPE. * 2) DEFINE PARAMETRIZED CONSTRUCTOR AND DISPLAY() METHOD * 3) CREATE CAR CLASS FROM VEHICLE WITH ATTRIBUTES: NUMBEROF DOORS, TRANSMISSIONTYPE. * 4) DEFINE THE PARAMETERIZED CONSTRUCTOR AND DISPLAY() METHOD IN CAR CLASS. * 5) CREATE ELECTRICCAR CLASS FROM CAR WITH ATTRIBUTES BATTERYCAPACITY AND CHARGINGTIME. DEFINE * PARAMETERIZED CONSTRUCTOR AND DISPLAY() METHOD. * 6) IN MAIN CLASS, CREATE AN ELECTRICCAR OBJECT, AND CALL THE DISPLAY() METHOD. */ package AIT.IO.Java; // Parent Class class Vehicle{ private int speed; private String fuelType; public Vehicle(int speed, String fuelType) { super(); this.speed = speed; this.fuelType = fuelType; } public void display() { System.out.println("The Speed of the car = "+speed+"KMPH"); System.out.println("The Fuel Type of the car = "+fuelType); } } // child class for vehicle class class Car extends Vehicle{ private int numberOfDoors; private String transmissionType; public Car(int speed, String fuelType, int numberOfDoors, String transmissionType) { super(speed, fuelType); this.numberOfDoors = numberOfDoors; this.transmissionType = transmissionType; } public void display() { super.display(); System.out.println("Number of Doors in a car = "+numberOfDoors); System.out.println("The Transmission Type of a car = "+transmissionType); } } // child class for Car class class ElectricCar extends Car{ private int batteryCapacity; private int chargingTime; public ElectricCar(int speed, String fuelType, int numberOfDoors, String transmissionType, int batteryCapacity, int chargingTime) { super(speed, fuelType, numberOfDoors, transmissionType); this.batteryCapacity = batteryCapacity; this.chargingTime = chargingTime; } public void display() { super.display(); System.out.println("The Battery Capacity of the Car = "+batteryCapacity+"KWH"); System.out.println("The Charging Time = "+chargingTime+"MINUTES"); } } public class Main { public static void main(String[] args) { ElectricCar ec = new ElectricCar(120,"Petrol",4,"Manual",120,60); ec.display(); } }