• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cant Compile abstract and interface class

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");

}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS alot it worked.
reply
    Bookmark Topic Watch Topic
  • New Topic