MULTILEVEL INHERITENCE:
class Employee1{
double salary = 50000;
void display() {
System.out.println("Employee Salary: Rs."+salary);
}
}
class firstSalary extends Employee1{
double increment = 0.50;
void totalSalary1() {
salary = salary +(salary * increment);
}
}
class secondSalary extends firstSalary{
double increment = 0.75;
void totalSalary2() {
salary = salary + (salary * increment);
}
}
public class Salary {
public static void main(String[] args) {
secondSalary s =new secondSalary();
System.out.println("Employee salary before increment: ");
s.display();
s.totalSalary1();
System.out.println("Employee salary after first year increment: "); s.display();
s.totalSalary2();
System.out.println("Employee salary after second year increment: ");
s.display();
}
}
HIERARICAL INHERITENCE:
class Employee{
double salary = 50000;
void display() {
System.out.println("Employee Salary: Rs."+salary);
}
}
class FullTimeEmployee extends Employee{
double hike = 0.50;
void fulltimeSalary() {
salary = salary +(salary * hike);
}
}
class InternEmployee extends Employee{
double hike = 0.25;
void internSalary() {
salary = salary +(salary * hike);
}
}
public class Main {
public static void main(String[] args) {
FullTimeEmployee emp1 = new FullTimeEmployee();
InternEmployee emp2 = new InternEmployee();
System.out.println("Salary of full-time employee before incrementing: ");
emp1.display();
System.out.println("Salary of intern before incrementing: ");
emp2.display();
emp1.fulltimeSalary();
emp2.internSalary();
System.out.println("Salary of full-time employee after incrementing: ");
emp1.display();
System.out.println("Salary of intern after incrementing: ");
emp2.display();
}
}