What will be the output of the following Java code?

class A 
   {
        int i;
    int j;
        A() 
        {
            i = 1;
            j = 2;
        }
   }
   class Output 
   {
        public static void main(String args[])
        {
             A obj1 = new A();
         System.out.print(obj1.toString());
        }
   }

a) true
b) false
c) String associated with obj1
d) Compilation Error

1 thought on “What will be the output of the following Java code?”

  1. c
    Explanation: toString() is method of class Object, since it is superclass of every class, every object has this method. toString() returns the string associated with the calling object.
    output:
    $ javac Output.java
    $ java Output
    A@1cd2e5f

Leave a Comment