Is there any other way
Without inserting the casting at each aPanel,
is there any other way to do this?
Inside the main, there is downcasting. Is there any other way
without casting...
package hiding.test;
publicclass ParentPanel{
public String aButton;
public ParentPanel(){
System.out.println("Hi, parent!");
}
publicvoid init(){
aButton =new String("aButtonAtParent");
System.out.println(aButton +"init() Parent");
}
}
package hiding.test;
publicclass ChildPanelextends ParentPanel{
public String aButton;
public ChildPanel(){
System.out.println("Hi, Child!");
}
publicvoid init(){
aButton =new String("aButtonAtChild");
System.out.println(aButton +"init() Child");
}
}
package hiding.test;
publicclass MainTest{
publicstaticvoid main(String[] args){
ParentPanel aPanel =new ChildPanel();
aPanel.init();
//-- Question ? : -
// without casting like this ( (ChildPanel) aPanel).aButton)
// is there any other way to do it?
System.out.println("===aPanel.aButton =" + ( (ChildPanel) aPanel).aButton);
}

