I have an object for a subclass who is of it's superclass type. There is a overridden function in subclass which gets executed when called using the object. How to call the parent's function using the same object? Is there any way to achieve this?
package supercall;
public class Main {
public static void main(String[] args) {
SomeClass obj = new SubClass();
obj.go();
}
}
class SomeClass {
SomeClass() {
}
public void go() {
System.out.println("Someclass go");
}
}
class SubClass extends SomeClass {
SubClass() {
}
@Override
public void go() {
System.out.println("Subclass go");
}
}
Consider the code above.
Here it prints
Subclass go
. Instead I have to print
Superclass go
.