Resources which teach Java seem to have conflicting answers on whether it's possible to both override a parent class's method and also create a new method from within a subclass at the same time. When I try the following:
class ABC{
//Overridden Method
public void disp(){
System.out.println("disp() method of parent");
}
}
class DEF extends ABC{
//Overriding Method
public void disp(){
System.out.println("disp() method of child");
}
//new method in the subclass
public void newMethod(){
System.out.println("new method of child class");
}
public static void main(String args[]){
ABC obj = new ABC();
obj.disp();
ABC obj2 = new DEF();
obj2.disp();
obj2.newMethod();
}
}
java throws a "cannot find symbol" error. Is there something I'm missing? It seems strange that one couldn't do both at once and yet I can't seem to escape that error.