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
posted
0
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
posted
0
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
posted
0
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
posted
0
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!