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

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

Moderator: admin

Post Reply
deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

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

Post 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.

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

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

Post by admin »

Because String class does have hashCode method.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Arold Aroldson
Posts: 21
Joined: Mon Nov 20, 2017 8:00 am
Contact:

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

Post by Arold Aroldson »

Yes it has hashCode method. But that method is part of Object class, isn't it?

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

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

Post by admin »

Object class does have hashCode method but String overrides it i.e. String provides its own version of this method.
If you like our products and services, please help us by posting your review here.

Arold Aroldson
Posts: 21
Joined: Mon Nov 20, 2017 8:00 am
Contact:

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

Post 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.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 99 guests