• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Interface

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,
I have a Little confusion. First feel free to correct me.

I think all the methods declare in a interface are public and abstract even the word �public� and �abstract� are not there.

Am I correct?
Because the answer given for the following question is 1, 3

public interface AQuestion
{
void someMethod();
}
The class which implements AQuestion
1. Should have someMethod which must necessarily be public.
2. Should have someMethod which could be "friendly" or public
3. Should have someMethod which should not throw any checked exceptions.
4. Should have someMethod which cannot be sychronized as sychronized is not in the signature of the interface defination
waiting for your reply.
vivek
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct. That's why 1) and 3) are correct.
Since the method is implicitly public so the class that implements this interface should necessarily have the public access modifier for this method else it'd be more restrictive than the original method in the interface. Hence 1) and 3) is obvious.
Chris
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
the modifiers final and synchronized can also be used in implementing methods so 4 is right too!!.

interface AQuestion
{
public void someMethod();
}
public class demo implements AQuestion
{ synchronized final void someMethod(){
}
}
Regds.
Rahul.
[This message has been edited by rahul_mkar (edited July 26, 2000).]
 
Chris Cleverley
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not forget to add public before the method in the implementing class as Rahul has done.
Chris
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahul_mkar:
Hi,
the modifiers final and synchronized can also be used in implementing methods so 4 is right too!!.

interface AQuestion
{
public void someMethod();
}
public class demo implements AQuestion
{ synchronized final void someMethod(){
}
}
Regds.
Rahul.
[This message has been edited by rahul_mkar (edited July 26, 2000).]


4 is not right BOSS ! u said it !
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we read the original answer 4 carefully, it says that someMethod cannot be synchronized. Rahul's code shows that someMethod() can be synchronized. Therefore 4 is incorrect, right?
 
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
Hi Deepak and Jim,
Both of you are right. One does have to read questions and answers very very carefully. I think in the test one does have sufficient time to do this.
Regds.
Rahul
 
reply
    Bookmark Topic Watch Topic
  • New Topic