Page 1 of 1
enthuware.ocajp.i.v7.2.1367
Posted: Fri Mar 16, 2018 10:45 am
by ashishrai.kv
Code: Select all
What should be inserted in the code given below at line marked //10:
class MyClass{
}
class MyComparable implements Comparable<MyClass>{
public int compareTo( *INSERT CODE HERE* x ){ //10
return 0;
}
}
here in interface<My Class> had mentioned, i have not found it in the book i was preparing from,
can you explain this problem in detail?
Re: enthuware.ocajp.i.v7.2.1367
Posted: Fri Mar 16, 2018 10:59 am
by admin
Sorry, I am not able to understand your question. Can you be more clear about what exactly are you asking?
Re: enthuware.ocajp.i.v7.2.1367
Posted: Fri Mar 16, 2018 11:24 am
by ashishrai.kv
what i mean can you give one more example like this are questions related to this type of questions
as i was not sure with the explanation given in mock why answer is not "Object" but "MyClass"?
Re: enthuware.ocajp.i.v7.2.1367
Posted: Sat Mar 17, 2018 10:49 pm
by admin
Well, it is a rule of Java language. If you type a generic interface to a particular type such as the case here (Comparable is being typed to MyClass), you have to use the same type while implementing methods of that interface.
Re: enthuware.ocajp.i.v7.2.1367
Posted: Wed Mar 21, 2018 10:06 am
by ashishrai.kv
ok thank you.