Skip to main content

Posts

Showing posts with the label Example

Java - Classes and Objects Example

Employee.java //Employee Class (Base class) public class Employee { int Empno; String name; String telephone; double basicsalar; double othrs; double otrate; double netSal; public double calcNetSalary(){ return basicsalar + othrs * otrate; } public void displayNetSalary() { netSal = basicsalar + othrs * otrate; System.out.println("Net Salary: "+netSal); } //Set name public void setName(String name) { this.name = name; } //Set telephone public void setTelephone(String telephone) { this.telephone = telephone; } //Set Empno public void setEmpno(int Empno) { this.Empno = Empno; } //Set OT hours public void setOthrs(double othrs) { this.othrs = othrs; } //Set OT Rate public void setOtrate(double otrate) { this.otrate = otrate; } //Set OT Rate public void setBasicsalar(double basicsalar) { this.basicsalar = basicsalar; } } Manager.java //Manager Class public class Manager extends Employee { ...