public class Animal {}
public class Dog extends Animal {
public void bark() { System.out.println("Woof"); }
}
Animal a = new Dog();
a.bark();What happens?
- Acheck_circle
Compile-time error: bark not in Animal
- B
Prints Woof
- C
Runtime error
- D
Prints nothing
Explanation
Method calls are checked against the declared (compile-time) type. Animal has no <code>bark</code>, so this fails to compile even though the object is a Dog.