Is it possible to override a class parameter in Java? I'm pretty sure it is not possible but...
public class Dad {
protected Building home;
public Dad() {
}
public Building getHome(){
return this.home;
}
}
public class Son extends Dad {
protected Shack home;
public Son () {
super();
this.home = new Shack();
}
}
public Shack extends Building{
(...)
}
Apparently, there is no problem in adding two paraters with the same name but i'm not sure the two parameters are "link" together..
When I'm calling the getHome()
function from a Son
object, it returns a null object. Which make sense because the Dad
object has no initialised Building
object. Even if Son
has a initialise Shack
object that extends Building
class. (I don't know if I'm clear enough...)
A simple solution would be to simply initialise home
with a Shack
object and cast home
in Shack
whenever it is necessary. But I'd like to know if there is another way to do this.