StringBuilder

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
sulakshana
Posts: 14
Joined: Thu Dec 22, 2016 8:55 pm
Contact:

StringBuilder

Post by sulakshana »

Stringbuilder s1= new StringBuilder("meow");
Stringbuilder s2 = new StringBuilder("meow");
if(s1 ==s2)System.out.println("one");
if(s1.equals(s2))System.out.println("two");
if(s1== "meow")System.out.println("three");
if(s1.toString() == "meow")System.out.println("four");
The answers are
Do not compile
Statement that do not compile is removed it prints "two"...
How it can print two when equals does not compile in stringbuilder....

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: StringBuilder

Post by admin »

Which line doesn't compile? All classes inherit equals method from Object class so why do you think s1.equals(s2) should not compile and should not return true?

Post Reply

Who is online

Users browsing this forum: Google [Bot], vs2013 and 3 guests