Ask Question
22 January, 03:34

Analyze the following code:

public class Test {

public static void main (String[] args) {

B b = new B ();

b. m (5);

System. out. println ("i is " + b. i);

}

}

class A {

int i;

public void m (int i) {

this. i = i;

}

}

class B extends A {

public void m (String s) {

}

}

A. The program has a compile error, because m is overridden with a different signature in B.

B. The program has a compile error, because b. m (5) cannot be invoked since the method m (int) is hidden in B.

C. The program has a runtime error on b. i, because i is not accessible from b.

D. The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

+4
Answers (1)
  1. 22 January, 06:40
    0
    Option D: The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B.

    Explanation:

    Method overriding in Java is done when you want a child class to give its own implementation to a method that is already provided by the parent class. The method in the parent class will be called overridden method, and the child class will be overriding method.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Analyze the following code: public class Test { public static void main (String[] args) { B b = new B (); b. m (5); System. out. println ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers