• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

mock exam errata

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Rishi
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rob Acraman
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u
for nice explanation.
 
I want my playground back. Here, I'll give you this tiny ad for it:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic