• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic