• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Implementing interfaces

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

the first chapter's two-minute drill (SCJP5, page 69) states at Interface Implementation, bullet #2:

"Interfaces can be implemented by any class, from any inheritance tree."

I think this is correct only if interfaces are declared as public. You can have a default interface as well, which is not visible by a class from a different package.

Am I right?

thanks,
Septimiu
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by septimiu pelau:
Hi there

the first chapter's two-minute drill (SCJP5, page 69) states at Interface Implementation, bullet #2:

"Interfaces can be implemented by any class, from any inheritance tree."

I think this is correct only if interfaces are declared as public. You can have a default interface as well, which is not visible by a class from a different package.

Am I right?

thanks,
Septimiu


Yes. You have to take access privileges into account.
 
Septimiu Pelau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then it's a good candidate for the errata, but that post was locked one year ago.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Interfaces are by dedault public and abstract.

So any where you can implement them even outside the package also
 
Septimiu Pelau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are confusing the access modifiers of interface methods with interfaces. While interface methods are indeed public and abstract implicitly the interfaces are only abstract. Therefore an interface can have the default access modifier (for this reason it must be declared within the same file with a public class or interface)
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right Sepitmul
 
Septimiu Pelau
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Virtank
 
Vikrant Sahdev
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You got my name wrong. I realized that I did that as well for you.
Hope you get it right now.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic