• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Java | Functions | Question 9

Predict the output of the following program. Java
 class Test
{

    public static void main(String[] args)
    {
        String obj1 = new String(\"geeks\");
        String obj2 = new String(\"geeks\");

        if(obj1.hashCode() == obj2.hashCode())
            System.out.println(\"hashCode of object1 is equal to object2\");

        if(obj1 == obj2)
            System.out.println(\"memory address of object1 is same as object2\");

        if(obj1.equals(obj2))
            System.out.println(\"value of object1 is equal to object2\");
    }
}

(A)

hashCode of object1 is equal to object2
value of object1 is equal to object2

(B)

hashCode of object1 is equal to object2
memory address of object1 is same as object2
value of object1 is equal to object2

(C)

memory address of object1 is same as object2
value of object1 is equal to object2

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments