Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

do they exist abstract interfaces?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i have been learning interfaces,

i have learnt interfaces have method declarations but no method body which is fine and they are also allowed attributes can be declared...

How ever thinking about it they are just abstract methods, i tried placing the abstract modifier in the method and it still complied..

here is the code

public interface House {
static int doorNumber=1;
public void repair();
public abstract void replaceWindows();
}

can some one please clarify the difference between these or are these the same?
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The abstract modifier is redundant on an interface.
All interface methods are implicitly public and abstract.
All interface fields are implicitly public, static and final.
All interface classes are implicitly public and static.
To explicitly specify any of these modifiers is poor form and results in death by firing squad (in a perfect world).
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi pally

every method in an interface is abstract by default. just like every variable in interface is "public static final" whether you declare it or not.. every method has to be "public abstract ". you cannot have static or final methods in interface. you cannot have protected abstract method in interface

but in abstract class ... you can have a abstract method which can be protected, default or public.

i hope this answers your doubt
regards
anuj
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony,

You posted that "All interface classes are implicitly public and static"

Is that correct? The interface itself is certainly not static. Did you mean "public and abstract"?
Or do you mean that whether you specify the static keyword or not when declaring an interface, the implementing class will be static? Does that make sense too?

Thanks,
Alex
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think when Tony said "interface classes", he meant nested classes defined in interfaces. Those are implicitly public and static. The same would be true for interfaces nested inside other interfaces. However interfaces which are not nested in other interfaces are not implicitly public or static. Nor are classes which extend such interfaces.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what Tony was that you can have inner classes and interface in the interface and those will be public and static.
May be this code will help you:



Thanks
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks Kalyani, jim and tony too!

it makes sense, classes (and interfaces) defined in the interface will be public and static.

Thanks,
Alex
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic