I'm a Java beginner and I can't understand when I should create an instance of the superclass or subclass. I'm studying some tutorials online and I found a few times something like the following code:
package test;
class ABC{
public void myMethod(){
System.out.println("Overridden Method");
}
}
public class test extends ABC{
@Override
public void myMethod(){
System.out.println("Overriding Method");
}
public static void main(String args[]){
ABC obj = new test();
obj.myMethod();
}
}
Why I should use ABC obj = new test();
instead of test = new test();
?
If I need a new ABC object wouldn't it make sense to just use ABC obj = new ABC();
?
Thank you, sorry for the noobie question.