Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Output of following Java Program? class Base {public void show() {System.out.pri

ID: 3835849 • Letter: O

Question

Output of following Java Program? class Base {public void show() {System.out.println("Base::show() called");}} class Derived extends Base {public void show() {System.out.println("Derived::show() called");}} public class Main {public static void main(String() args) {Base b = new Derived!);; b.show();}} Output of following Java Program? class Base (final public void show() {System.out.println("Base::show() called");}} class Derived extends Base {public void show() {System.out.println("Derived::show() called");}} class Main {public static void main(String() args) {Base b = new Derived(); b.show();}}

Explanation / Answer

1)
Answer:Derived::show() called

explanation:
In the above program, b is a reference of Base type and refers to an abject of Derived class.
In Java, functions are virtual by default. So the run time polymorphism happens and derived fun() is called.

2)
Answer: Compile time error

Explanation: show() in Derived cannot override show() in Base
   public void show() {
   ^
overridden method is final

since Final methods cannot be overriddenso we See the compiler error here.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote