• 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

Abstract class and interfaces.

 
Ranch Hand
Posts: 41
Android Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following questions of Interfaces and Abstract classes.

1. Why is a protected interface not allowed?

2. Interface methods are implicitly public and abstract, can I ?

3. Why can't I specify "default" access specifier for an interface (it is only implicit when I do not say "public", but I cannot say "default interface test{}"

4. What happens when I do not provide the "public" keyword for an interface and it does not belong to any package? Who can access it?

5. I have a group of Interfaces and Abstract class (.java) files in a folder. I do javac *.java - how does the compiler resolve the order before compiling?

Regards
Sanjeev
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanjeev Bhima Rao wrote:1. Why is a protected interface not allowed?


You mean declaring the interface protected or the methods inside the interface as protected? No top level class/interface/enum can be declared as protected.

2. Interface methods are implicitly public and abstract, can I ?


Can you what?

3. Why can't I specify "default" access specifier for an interface (it is only implicit when I do not say "public", but I cannot say "default interface test{}"


default is not a valid access specifier. default keyword is used in switch-case statement not to specify scope of an object (applies to classes as well).

4. What happens when I do not provide the "public" keyword for an interface and it does not belong to any package? Who can access it?


Only other classes which are not in any package (applies to classes as well)

5. I have a group of Interfaces and Abstract class (.java) files in a folder. I do javac *.java - how does the compiler resolve the order before compiling?


The compiler will compile the classes/interfaces in alphabetical order and if it comes to a class/interface which uses another class/interface, that one is compiled first...
 
Sanjeev Ba
Ranch Hand
Posts: 41
Android Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. I meant the interface (not the methods). I need to know why.

2. Sorry for missing the question. Can I have protected interface methods? Why?

Thanks for the answers to the rest of the questions.

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

Ankit Garg wrote:

Sanjeev Bhima Rao wrote:4. What happens when I do not provide the "public" keyword for an interface and it does not belong to any package? Who can access it?


Only other classes which are not in any package (applies to classes as well)




In practice though, aren't the classes which aren't explicitly in a package put in a "default" package? I seem to recall reading this somewhere...

// Andreas
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andreas Svenkson wrote:In practice though, aren't the classes which aren't explicitly in a package put in a "default" package? I seem to recall reading this somewhere...


Yes, that's right. But you can't import the default package, so only other classes that are in the default package can use them.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic