Ask Question

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. 25 December, 23:15
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers