public class A {
public String tag() { return "A"; }
}
public class B extends A {
public String tag() { return "B"; }
public String extra() { return "extra"; }
}
// Usage:
A obj = new B();
System.out.print(obj.extra());What occurs?
- A
Prints 'B'
- B
Prints 'extra'
- C
Runtime error
- Dcheck_circle
Compile error: A has no extra() method
Explanation
Methods callable on obj are limited to those declared in A (the static type). extra() exists only in B, so the compiler reports an error.