class Employee1{ String name; double salary; public Employee1(String name,double salary){ this.name = name; this.salary = salary; } public double ComputeSalary(){ return salary; } } class Manager extends Employee1{ double bonus; public Manager(String name,double salary,double bonus){ super(name,salary); this.bonus = bonus; } public double ComputeSalary(){ return super.ComputeSalary() + bonus; } } public class polymorphism{ static void printSalary(Employee1 emp){ System.out.println(emp.name+"total salary"+emp.ComputeSalary()); } public static void main(String[]args) { Employee1 emp1 = new Employee1("Arun",5000); Manager man1 = new Manager("Tharun",4000,9000); printSalary(emp1); printSalary(man1); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter