Question: Assume the classes Base, Derived, and Test are defined as indicated below. What happens when we compile and run Test? public class Base {} public

Assume the classes Base, Derived, and Test are defined as indicated below. What happens when we compile and run Test?

public class Base {} public class Derived extends Base {} public class Test {  public static void main(String[] args) {  Base b = new Derived();  g(b);  }  public static void g(Base b) {  System.out.println("g(Base)");  }  public static void g(Derived d) {  System.out.println("g(Derived)");  } }

Question 4 options:

An error occurs when you try to compile.

An exception is thrown when you try running Test.

g(Base) is displayed to the screen

g(Derived) is displayed to the screen

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!