Ask Question
20 November, 21:32

When executing System. out. println (a2), the toString () method in the Object class is invoked. The program cannot be compiled, because System. out. println (a1) is wrong and it should be replaced by System. out. println (a1. toString ()); When executing System. out. println (a1), the toString () method in the Object class is invoked. When executing System. out. println (a1), the toString () method in the A class is invoked. True or false?

+4
Answers (1)
  1. 20 November, 21:46
    0
    in the code snippet below, c. When System. out. println (a2) is executing, the toString () method is called.

    d. When System. out. println (a1) is executing, the toString () method in class A gets called.

    Explanation:

    public class Test{

    public static void main (String[] args) {

    Object a1 = new A ();

    Object a2 = new Object ();

    System. out. println (a1);

    System. out. println (a2);

    }

    }

    class A{

    int x;

    @Override

    public String toString () {

    return "A's x is " + x;

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “When executing System. out. println (a2), the toString () method in the Object class is invoked. The program cannot be compiled, because ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers