• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant Compile abstract and interface class

 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the error below when i try to compile this program. Can some one tell me what am i doing wrong and how should i fix the error?

test2() in testing cannot implement test2() in I1; attempting to assign weaker access privileges; was public
void test2(){
^
1 error




abstract class A1{
abstract void test();
}

abstract class A2 extends A1{
}

interface I1{
void test2() ;

}


class testing extends A2 implements I1{
void test(){
System.out.println("HELLO THERE FROM TEST1");
}
void test2(){
System.out.println("HELLO THERE FROM TEST2");
}
}



public class AbsExample1{




public static void main(String[] args){
testing one=new testing();
one.test();
one.test2();
System.out.println("accessing main");

}
}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All methods in an interface are implicitly public, whether you mark them as "public" or not. That means that the methods in any classes that implement those interfaces must also be public; you can't implement an interface method with a non-public method. Your "void test2()" must be "public void test2()".
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THANKS alot it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic