I saw an example that try to explain inheritance in Java. The class Employee, which is the base class, has three instance variables and three constructors. it is as follows:
public class Employee{
private String name;
private int id;
public Employee(){
name = " No Name!";
id = 00100;
}
public Employee(String n, int i){
name = n;
id = i;
}
public Employee (Employee originalObject){
name = originalObject.name;
id = originalObject.id;
}
My question is : What's the point of the third constructor? and how it accepts an argument with the same type, Employee
,of the class that we are still working on ? The program has already an empty constructor and another one that passes String for name
and int
for id
, so why there is an extra one that does no much more than the previous two constructors ?