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.
About Question enthuware.ocajp.i.v7.2.1336 :
Moderator: admin
-
- Posts: 15
- Joined: Thu Dec 13, 2012 9:44 am
- Contact:
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1336 :
Because String class does have hashCode method.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 21
- Joined: Mon Nov 20, 2017 8:00 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1336 :
Yes it has hashCode method. But that method is part of Object class, isn't it?
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1336 :
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.
-
- Posts: 21
- Joined: Mon Nov 20, 2017 8:00 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1336 :
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.
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1336 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: mcpunjabi and 47 guests