D
DeeGoogle
I know this is not possible, but my question is why did they design it
that way:
public class ParentForm {
protected String name = "ParentForm";
protected String getName(){return name;}
}
public class ChildForm extends ParentForm{
protected String name = "ChildForm"; //I am trying to override
the field value but reuse the method from parent.
}
public class Test {
public static void main(String[] args) {
System.out.println((new ParentForm()).getName());
System.out.println((new ChildForm()).getName());
}
}
Output:
ParentForm
ParentForm
I wanted to see "ChildForm" in the second line. Why do I have to
duplicate (literally cut and paste) the getName() method in the child
to achieve it ?
Can someone explain the concept I am missing ?
that way:
public class ParentForm {
protected String name = "ParentForm";
protected String getName(){return name;}
}
public class ChildForm extends ParentForm{
protected String name = "ChildForm"; //I am trying to override
the field value but reuse the method from parent.
}
public class Test {
public static void main(String[] args) {
System.out.println((new ParentForm()).getName());
System.out.println((new ChildForm()).getName());
}
}
Output:
ParentForm
ParentForm
I wanted to see "ChildForm" in the second line. Why do I have to
duplicate (literally cut and paste) the getName() method in the child
to achieve it ?
Can someone explain the concept I am missing ?