If there are two methods with same name in Parent class and Child Class, for example:
Parent class:
public abstract class Employee implements Payments {
private String name;
protected double basicSalary;
public Employee(String name, double basicSalary) {
this.basicSalary = basicSalary;
this.name = name;
}
public void display() {
System.out.println( " Name: " + name + " - Basic Salary: " + basicSalary +"SR" );
}
}
Child class:
public class Faculty extends Employee {
private String degree;
private int teachingHours;
public Faculty(String name, double salary, String degree, int teachingHours) {
super(name, salary);
this.degree = degree;
this.teachingHours = teachingHours;
}
public void display() {
System.out.println( " Name: " +getName() + " - Degree:" +degree);
}
And I create an object like this:
Employee[] arrEm = new Employee[4];
arrEm[0] = new Faculty("ahmad", 1000, "Phd", 10);
So if I write
arrEm[0].display();
this way the method display()
will be used in child. But in case we want to use the method display in Parent Class, how can it be done?
Thanks in advance !