Download to read offline



![class Employee{
protected float salary=40000;
Public void cetakGaji(){
System.out.println(“gaji : ”+salary);
}
}
class Programmer extends Employee{
private float bonus=10000;
Public void cetakTotalGaji(){
System.out.println(“gaji : ”+salary);
}
}
public static void main(String args[]){
Programmer p=new Programmer();
p.cetakGaji();
p.cetakTotalGaji();
}](https://image.slidesharecdn.com/objectorientedprograming-inheritance-161024084619/75/Object-Oriented-Programing-Inheritance-4-2048.jpg)



This code defines an Employee class with a protected salary field and method to print the salary. It also defines a Programmer class that extends Employee, adds a private bonus field, and overrides the salary printing method to print the total salary which is the sum of the inherited salary and local bonus fields. The main method creates a Programmer object and calls both the parent and child class's salary printing methods.



![class Employee{
protected float salary=40000;
Public void cetakGaji(){
System.out.println(“gaji : ”+salary);
}
}
class Programmer extends Employee{
private float bonus=10000;
Public void cetakTotalGaji(){
System.out.println(“gaji : ”+salary);
}
}
public static void main(String args[]){
Programmer p=new Programmer();
p.cetakGaji();
p.cetakTotalGaji();
}](https://image.slidesharecdn.com/objectorientedprograming-inheritance-161024084619/75/Object-Oriented-Programing-Inheritance-4-2048.jpg)

