Given the following defn which of the defination are valid? interface I{ void setValue(int i); int getValue(); } select all valid answers: i) interface B extends I{ void increment(); } ii) abstract class c implements I{ int getValue(){ return 0; } abstract void increment(); } i am not providing u all the option pls tell me my second option is right or wrong? i think it is right?
It's NEARLY right Interface methods are implicitly public, and so any class that implements them must also declare them to be public (since sub-classes cannot make anything they inherit less public than it was declared in the super-class). So, just make getValue() public, like so:
Hi Rishi, IN interface methods are implicitly public Now , in the abstarct class you are overridding one method and restricting the access (from public to package ) Hope that helps:-) regds NM ------------------ "Knowledge is Power"****************MY SCJP RESOURCES
"Knowledge is Power"****************<A HREF="http://www.geocities.com/nityananda_mukherjee" TARGET=_blank rel="nofollow">THREAD/SCJP RESOURCES</A>
Just thought I'd also make mention this: The question above is very tricky, in that it's really testing you on 2 levels: - "Explicitly" testing your understanding of abstract classes and interfaces - A subtler test of "public" and permissions. These type of questions DO occur in SCJP, so make sure you keep your wits about you. Good Luck