File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Interface" Watch "Interface" New topic
Author

Interface

Vivek Shrivastava
Ranch Hand

Joined: Jun 03, 2000
Posts: 277

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
Chris Cleverley
Greenhorn

Joined: Mar 09, 2007
Posts: 22
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
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 09, 2007
Posts: 22
Do not forget to add public before the method in the implementing class as Rahul has done.
Chris
Deepak M
Ranch Hand

Joined: Jul 10, 2000
Posts: 124
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 !
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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?

"I'm not back." - Bill Harding, Twister
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
 
 
subject: Interface