What will be the output of the following Java program?

class string_class 
   {
       public static void main(String args[])
       {
           String obj = "hello";
           String obj1 = "world";   
           String obj2 = "hello";
           System.out.println(obj.equals(obj1) + " " + obj.equals(obj2));
       }
   }

a) false false
b) true true
c) true false
d) false true

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

  1. d
    Explanation: equals() is method of class String, it is used to check equality of two String objects, if they are equal, true is retuned else false.
    output:
    $ javac string_class.java
    $ java string_class
    false true

Leave a Comment