• 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

interface scope

 
Ranch Hand
Posts: 528
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Kalid Mughal's book (second edition), it doesn't actually specify what scope interface can have.

An interface can obviously not be private, nor protected, but is it implicitly public? or default? And what can you explicitly specify?
 
author
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like a class, an interface is implicitly default and can be public. An inner interface can have any access mode.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marzo, please change your displayed name to conform with our JavaRanch Naming Policy.

We require a display name in the format <first name><space><family name> or <initial(s)><space><family name>.

Thanks
-Barry

(NR 1)
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An interface is not implicitly default.
An interface can have any one of the four access scopes.
Context is paramount.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... I'm replying to a post of Tony's without disagreeing in any way. I'm afraid my brain may implode. Nonetheless, I completely agree with his last post, I just have some other comments to add:

[Marzo]: In Kalid Mughal's book (second edition), it doesn't actually specify what scope interface can have.

Mmmm... scope is a somewhat different concept than access. For example the scope of a method is the class it's defined in. But if it's public, it's accessible from anywhere. All the subsequent discussion seems to be about access, not scope, so I'm going to assume you meant access in the first place.

[Philip]: An inner interface can have any access mode.

A nested interface can have any access mode. There's no such thing as an inner interface, since nested interfaces are implicitly static, and static classes cannot be inner classes, by definition. This may well seem like minor semantic quibbling (Hi, I'm Jim, pleased to meet you) - for the SCJP, there are no questions that depend on understanding the distinction between nested and inner classes. However if you're ever reading the JLS and trying to understand something it says, it's important to understand that inner classes and nested classes are not the same thing. When it says, for example, that "Inner classes may not declare static members, unless they are compile-time constant fields" - it's assumed that you know that a static member class is not an inner class. A static member class certainly can define static members, but a true inner class cannot.
[ June 17, 2005: Message edited by: Jim Yingst ]
 
Marcelo Ortega
Ranch Hand
Posts: 528
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry i meant access modifer. So then i assume the following is correct:

A 'top level' interface can ONLY have either default or public access.

Correct?
Because if i try to use anything else i get a compile-time error.

And Barry, this is my name (Marzo) and my initials are O.C.

Cheers, Marzo.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was an excellent post Jim. Keep it up

 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


A 'top level' interface can ONLY have either default or public access.

Correct?


Correct (note that you have provided context).
 
Marcelo Ortega
Ranch Hand
Posts: 528
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankx Tony, thats clear now, but what about top level abstract classes?
Does the same go for them, i.e they are only allowd to be declared as public or default?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marzo O.C:

And Barry, this is my name (Marzo) and my initials are O.C.



Ok, then it's easy. Change your displayed name to "O.C. Marzo". I understand then that your first names have initials O and C and your family name is Marzo.

That's our convention on JavaRanch. Using this convention my displayed name would be "B. F. Gaunt", if I wished to use initials for my first names.

It's not just you, I'm after "Chitra AP" next when he pops in again .

Thanks.
-Barry
[ June 17, 2005: Message edited by: Barry Gaunt ]
 
Marcelo Ortega
Ranch Hand
Posts: 528
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that better Barry?

Any comments on my last post?
I think i have it clear though, ANY 'top level' class, interface or abstract class must either be public or default...

Correct?

Cheers.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marzo Kaahn:
Is that better Barry?



Perfect!



I'll have more time for the interesting task of trying to answer one or two java questions.
[ June 17, 2005: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marzo Kaahn:

I think i have it clear though, ANY 'top level' class, interface or abstract class must either be public or default...

Correct?



Yes, that's correct.
[ June 17, 2005: Message edited by: Barry Gaunt ]
 
please buy my thing and then I'll have more money:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic