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

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 » Thu Jun 06, 2013 3:10 pm

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.

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

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

Post by admin » Fri Jun 07, 2013 7:42 pm

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 » Thu Nov 15, 2018 3:45 am

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

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

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

Post by admin » Thu Nov 15, 2018 4:45 am

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 » Thu Nov 15, 2018 5:01 am

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.

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

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

Post by admin » Thu Nov 15, 2018 9:08 am

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: admin and 2 guests