aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes From Khalid's Book (Question on interfaces) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "From Khalid Watch "From Khalid New topic
Author

From Khalid's Book (Question on interfaces)

Rahul Mehta
Greenhorn

Joined: Dec 13, 2000
Posts: 1

Here goes the question :
what is wrong ,if anything with the folloeing code:
abstract class MyClass implements Interface1,Interface2{
void f(){};
void g(){};
}
interface Interface1{
int VAL_A = 1;
int VAL_B = 2;
void f();
void g();
}
interface Interface2{
int VAL_B = 3;
int VAL_C = 4;
void g();
void h();
}
According to the book , the code should compile without any errors but when I tried to compile it . It gave following error:
g() in MyClass cannot implement g() in Interface1; attempting to assign weaker access privileges; was public
Can anyone explain me the error.
TIA
Rahul
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158

Ahaaa. That had happened to me a few times. It does not work until you change the access levels of the methods in MyClass to
public . Always intended to find out why. I'll poke around in the JLS and let you know if I come up with something.

cheers
Sahir


....
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158

Nothing in JLS. Tried putting them in same package, different package , messed with the class path , using import, export.
No dice. Stumped ! Any ideas guys?
rgds
Sahir
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
I remember that interfce methods are implicitly public, correct me if I'm wrong.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Absolutely! All interface methods are public by default and since you didn't specify anything in the class you were trying to redefine them as package. Bzzzt! Not permitted!


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Sahir Shah
Ranch Hand

Joined: Nov 05, 2000
Posts: 158

Aaah! So that was it. Thanks guys.
Rgds
Sahir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: From Khalid's Book (Question on interfaces)