public class Animal {}
public class Dog extends Animal {
public void bark() { System.out.println("Woof"); }
}
Animal a = new Dog();
((Dog) a).bark();What is printed?
- Acheck_circle
Woof
- B
Compile-time error
- C
ClassCastException
- D
nothing
Explanation
The object is actually a Dog, so the downcast succeeds and bark() runs.