Yes. Assuming the classes remain in the same package – x.getVal will work.
class A {
String getVal(){
return "from a";
}
}
class B extends A {
}
public class C {
public static void main(String [] args) {
B x = new B();
x.getVal();
}
}
It works – because of the default access modifier. Use the protected
access modifier for inheritance.
solved How to call another classes super class? [closed]