The IT Certification Resource Center

Featured Deal

Get CompTIA, Cisco, and Microsoft training courses free for a week.
Learn More ❯

Question 29:

What will happen when you attempt to compile and run the following code snippet?

String str = "Java";
    StringBuffer buffer = new StringBuffer(str);
    
    if(str.equals(buffer))
    {
        System.out.println("Both are equal");
    }
    else
    {
        System.out.println("Both are not equal");
    }

A. It will print - Both are not equal
B. It will print - Both are equal
C. Compile time error as you can not use equals for objects of different classes
D. Runtime error as you can not use equals for objects of different classes
E. None of these