Question :Have a look at the following code.
How do I execute the method d() in class B without creating another
instance in the main method.
class A {
void c() {
System.out.println("In A class");
}
}
public class B extends A {
void d() {
System.out.println("In B class");
}
public static void main(String args[]) {
A a = new B();
}
}
(CoreJava)
Answer :you will need to typecast the object to ((B)a).d();
No comments:
Post a Comment