GS311-CS602 Ms Halima Atiya OOP Example (Lecture 3) //main class public class Company { public static void main(String[] args) { // TODO code application logic her employee1 emp1= new employee1("IVY",001,2000); employee2 emp2= new employee2("john",002,2000,600); System.out.printf("name is :%S\nemp_no:%d\nsalary: %f\n total salry :%.2f",emp1.name,emp1.employeeno,emp1.salary,emp1.earning(6)); System.out.printf("\nname is :%s\nemployee_not:%d\nsalary:%.2f\ntotal with additon: %.2f", emp2.name,emp2.employeeno,emp2.salary,emp2.earning(6)); emp1.setname("Farah"); System.out.printf("\nname: %S", emp1.getname()); }
} //java class 1 //package company;
public class employee1 {
String name; int employeeno; double salary; double total;
//constructor
public employee1(String n,int em,double s) { name= n; employeeno= em; salary= s; }
//set public void setname(String n) { name=n; } //get public String getname()
{ return name; } //function to calculate the salary public double earning(int months) { return total=salary*months; } }
//Java class 2 //package company;
public class employee2 extends employee1 { double addition;
//constructor public employee2(String n, int em,double s, double a) { super(n,em,s); addition=a; } public double earning(int months) { return super.earning(months)+addition; } }