Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Disguised {
@Override
public Class<?> getClass() { return String.class; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new Disguised().getClass());
}
}
- A Class<?> is not a type
- B getClass() is final in Object, so it cannot be overridden Correct
- C String.class does not exist
- D Disguised needs a constructor
Correct Answer: Option B
This guarantees getClass always reports the real class.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!