File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Cant Compile abstract and interface class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cant Compile abstract and interface class" Watch "Cant Compile abstract and interface class" New topic
Author

Cant Compile abstract and interface class

jo sim
Ranch Hand

Joined: Apr 24, 2006
Posts: 37
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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()".


[Jess in Action][AskingGoodQuestions]
jo sim
Ranch Hand

Joined: Apr 24, 2006
Posts: 37
THANKS alot it worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cant Compile abstract and interface class