Let's say I have the following code:
public class Employee
{
public int salary = 2000;
public void getDetails() {...}
}
public class Manager extends Employee
{
public int salary = 5000;
public int allowance = 8000;
public void getDetails() {...}
}
and a main(), which performs the following actions:
Employee emp = new Employee();
Manager man = new Manager();
emp.getDetails();
man.getDetails();
Employee emp_new = new Manager();
emp_new.getDetails();
System.out.println(emp_new.allowance);
System.out.println(emp_new.salary);
The book says: "You get behavior associated with the object that the variable belongs to at run time." Ok, I get the behavior of the Manager class when the method is called getDetails, but when I access the attribute salary, I get the behavior of a variable, not an object. Why is this?
source
share