Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Help, exam in 2 days!

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone tell me why this is happening here.
When I compile the following code I get an error "The method void aMethod() declared in class Test cannot override the method of the same signature declared in interface A. The access modifier is made more restrictive."
The code is in one source file (called Test.java) but the same happens when it is split into four separate files.

I don't understand why this is happening. The access modifier for the method is "friendly" and the class & interface are in the same, default, package so why the problem?
The only way I can compile this file is by making the method declaration in class Test public.
I thought I understood access modifiers but this has thrown me. Please help me understand this because I've got my exam on Wednesday.
Thank you,
Lee.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lee,
the default modifiers for any interface are always public (for fields and methods).
Moreover, interface methods can't be native, static, synchronized, final, private, or protected.
 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your speedy reply, yanish. You've put my mind at rest.
I'm amazed that no matter how much you think you know, there's always something manages to surprise you.
Thanks again,
Lee
reply
    Bookmark Topic Watch Topic
  • New Topic