• 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

Weather Interface is public by default

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while going through link

https://coderanch.com/t/191196/java-programmer-SCJP/certification/abstract-Vs-interface

i found that it is written there :

4. Interface is public by default but abstract is not.

Is that right , i am confused and think that is is not true.

What do you all say.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, interfaces are public by default, just like top level classes must be either public or default.
Methods in interface are abstract and public by default.
and variabels are public static final, you can't explicitly give them other modifiers.
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interface is abstract by default.

interface Inter{}
abstract interface Inter{}

Above two interface declaration are same.

If interface is not public then it is default (package level)

public interface Inter{} //public interface
interface Inter{}//package level interface(will be accessed within package only)
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi gaurav,

Interfaces are not public by default. However, methods and named constants which you declare in interfaces are public by default.

You can check this from SCJP 1.5 by K&B on page 20

Naseem
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks , it helps me a lot.
 
Bartender
Posts: 3903
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ram gaurav:
while going through link

https://coderanch.com/t/191196/java-programmer-SCJP/certification/abstract-Vs-interface

i found that it is written there :

4. Interface is public by default but abstract is not.

Is that right , i am confused and think that is is not true.

What do you all say.



It's just bad English problem.

Here is how it should be (IMHO):

Interface [methods] are public by default but abstract [class methods] are not.

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great job, Mikalai!

Exactly right.

About interface access levels:

Top-level interfaces can have public or default access.

Inner interfaces (like inner classes) can have public, protected, default or private access.

Method local interfaces are always default access, which could be misleading a little, since they can only be used in the method they are declared in (same scoping as automatic variables).
[ July 13, 2006: Message edited by: Douglas Chorpita ]
reply
    Bookmark Topic Watch Topic
  • New Topic