• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

from Abhilash Quiz. Question # 9

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public interface AQuestion
{
void someMethod();
}
The class which implements AQuestion
a. Should have someMethod which must necessarily be public.
b. Should have someMethod which could be "friendly" or public
c. Should have someMethod which should not throw any checked exceptions.
d. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface defination.
The answer given is a and c, but IMO answer should be b,c.
can anybody explain, how the answer a is correct.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear S
Think of a interface as a INTERFACE, i.e., it has to be available to every user. So a method inside a interface is public and there is no way you can narrow down the access. Hence, answer a is correct.
Hope this helps
Sanjeev
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every method declaration in the body of an interface is implicitly public and abstract.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But why it cannot throw checked exception ? Can any body please explain?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Implementing interface methods in a class is like overriding methods. And as far as overriding is concerned
1. The overriding and overridden methods must have same return type
2. The accessibility of the overriding method must not be more restrictive than the overridden method
3. The throws clause of the overriding method MUST only specify exceptions ( or less ) that are in the throws clause of the overridden method.
I think 3rd point should clear you doubt.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saying simply, the delaration of a method in an interface should point out all the potencial exceptions the implemented method will throw in all classese that implement the interface.
 
reply
    Bookmark Topic Watch Topic
  • New Topic