Start learning 50% faster. Sign in now
This program demonstrates runtime polymorphism in Java through method overriding. When the method display() is called on the object obj, the overridden method in class B is executed. This is because obj is instantiated as new B(), and at runtime, the JVM determines the appropriate method to execute based on the actual type of the object. Thus, even though obj is declared as type A, the overridden display() method in B is executed, producing the output "Class B" . This behavior is a key feature of Java's dynamic method dispatch mechanism. Explanation of Incorrect Options: A) Class A : This would be true if the display() method in class B was not overridden. However, since B overrides A's method, this option is incorrect. C) Compilation Error : The code is syntactically correct, so it compiles without any issues. D) Runtime Error : The program runs successfully, as all method calls are valid and properly resolved at runtime. E) None of the above : This is incorrect, as the correct output is explicitly "Class B" .
which of the following combination is true?
Which of the following statements is true about the one who likes Watermelon?
Four of the following are alike in a certain way. Who among the following does not belong to the group?
Which of the following statements is correct?
Who belongs to Assam?
Who among the following is senior to SI and junior to ASP?Â
Seven persons J, K, L, M, N, O and P attend seminar on seven different days of a week starting from Monday. P attends seminar on Friday. L attends semin...
Who among the following live on the floors between the floors on which Ji-hu and Min-ho live?
...Who among the following likes Black?