Answer the question
In order to leave comments, you need to log in
Why can't I use the methods of an object of class B (a descendant of A) creating an instance like this "A object = new B()"?
class A{
void printAString(){
System.out.println("a string");
}
}
class B extends A{
void printBString(){
System.out.println("b string");
}
}
class Test1{
public static void main(String[] args){
A object = new B();
System.out.println(object.getClass());
object.printAString();
object.printBString();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question