Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Thu Jun 06, 2013 3:10 pm
by deepa.patre
In this question "Which of these methods are not a part of the String class?"
options: trim(), length(), concat(String), hashcode(), reverse().

I think there are two answers for this question - hashcode() and reverse() but why only reverse() is correct.

Re: About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Fri Jun 07, 2013 7:42 pm
by admin
Because String class does have hashCode method.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Thu Nov 15, 2018 3:45 am
by Arold Aroldson
Yes it has hashCode method. But that method is part of Object class, isn't it?

Re: About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Thu Nov 15, 2018 4:45 am
by admin
Object class does have hashCode method but String overrides it i.e. String provides its own version of this method.

Re: About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Thu Nov 15, 2018 5:01 am
by Arold Aroldson
Okay. But what if (just for example) String class didn't override it? Can we say that hashCode method is part of String class? I'm confused in terminology.

Re: About Question enthuware.ocajp.i.v7.2.1336 :

Posted: Thu Nov 15, 2018 9:08 am
by admin
It would be really ambiguous in that case. If the question said "a part of the code of the String class", then no, it wouldn't be part of the code on the class but it would still be considered part of the string class because String class would inherit the method. I am just trying to split hair here but if it comes to that then this is what I would go with. I don't think you need to worry about this too much.

HTH,
Paul.