What will be the output of the following Java program? [code] class A { int i; int j; A() { i =

KellyPoima

New member
What will be the output of the following Java program?
Code:
   class A 
   {
	int i;
	int j;
        A() 
        {
            i = 1;
            j = 2;
        }
   }
   class Output 
   {
        public static void main(String args[])
        {
             A obj1 = new A();
             A obj2 = new A();
	     System.out.print(obj1.equals(obj2));
        }
   }
A. false
B. true
C. 1
D. Compilation Error
 
Answer: a
Explanation: obj1 and obj2 are two different objects. equals() is a method of Object class, Since Object class is superclass of every class it is available to every object.
output:
Code:
$ javac Output.java
$ java Output
false
 

Tìm kiếm

Back
Top