When I have these classes:
public class Master{
public String test(){
return "I am the master object";
}
public String boeh(){
return "Only inside master";
}
}
public class Slave extends Master{
public String test(){
return "I am the slave object";
}
public String mehh(){
return "Only insde slave";
}
}
I know I can do this: Master jedi = new Slave() (because Slave is a child type of Master).
And because I can... Why do I get "I am the slave object" while the variable is set to Master. And I get the result of Slave.test() but can't access Slave.mehh().
So whats the reason to give a variable a type when its ignored this why? Or in other words when Master jedi is actually Slave jedi what function does it has to declare Master?
dynamic method binding, can't accessSlave.mehh()- because, you can access only the methods that are overridden in the child class.