Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Kathy Book - Declarations and Access Control Doubt

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Goodday!
I have some doubts about
Question 1:
As we know interface method is implicitly public
abstract.How about the interface declaration?
sample:
public abstract interface Rollable{}
From Kathy Book page 115 chap2, it
stated that the interface is implicitly abstract.
Fact A:
Later, it stated that "The public modifier is required if you want the interface to have public rather than default access."
End Fact A
Fact B:
But at the end of the chapter, Pg 133
Interface implementation section:
"Interface are by default public and abstract-
explicit declaration of these modifiers is optional"
End Fact B
What is the default modifiers for interface and
what is modifier allowed to change the default access,e.g rivate,protected or default access.
Please enlighten me!
Thanks.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An interface can have default/public access.But any method u declare in an interface is public by default.
What this means is, if u declare an interface as public but do not specify any access modifier for the methods defined in it,
u will still be able to access these methods in any class implementing the interface irrsepective of the package in which the class is.
On the other hand, if u do not specify the interface as public, u will not be able to access it outside its package though the methods in it are specified as public.
To sum up, U have to explicitly state that an interface is public if u want to access it outside its package...but u can drop the access modifier in case of methods.
hope this helps..
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajeshwari is perfect in her explanantion. I just want to streach it to include more.
Interfaces are static by default. If you declare a interface inside a method local inner class you get compiler error. How ever you can't define a top level interface with static specifier.
Also all variables defined inside an interface are implicitely public staitc final. You can define any variable with any or all the 3 words in any order.
All the methods in the interface are implicitely public and abstract. You can define a method with any or both or without any of the two qualifying words.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarma,
Are you sure that interfaces are static by default? I could be wrong, but I was under the impression that interfaces can never be marked static. Take a look at Kathy's book - p.103. Here interfaces is listed in the section, "Things you can't mark static"
Mansi
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mansi, Did you try this???
Interfaces are static by default. If you declare a interface inside a method local inner class you get compiler error. How ever you can't define a top level interface with static specifier.
 
Replace the word "snake" with "danger noodle" in all tiny ads.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic