• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Interfaces Vs Abstract Classes

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that a superclass declared as abstract has abstract methods in it, and a subclass which extends should either override all methods present in the superclass or itself be declared as abstract...
Further, In interfaces you have method definitions, which should be
implemented(all methods should be implemented by using public keyword)

Now My question???
i dont find any difference between the structure of abstract classes and interfaces(If you find one , let me know)???
Then why cant you only have either one of the two???
Why does java give you both abstract classes and interfaces???
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This topic has been discussed on a regular basis here at the Ranch. You should use the search tool to find the previous threads.

With that said, I'd like to clarify that an abstract class doesn't *have* to have abstract methods. You can give definitions for every method in a class that is declared as abstract. On the other hand, even a single abstract method implies that the enclosing class is abstract, even if it isn't explicitly declared as such. Typically, an abstract class has both abstract methods and non-abstract methods. In contrast, all methods in an interface are abstract. You cannot have any executing code in an interface.

Also, remember that you can only extend a single class. However, you can implement more than one interface. This is Java's simplification of multiple inheritence that is available in other Object Oriented languages, like C++ and SmallTalk.

Anyway, I won't go into any more detail since you should be able to find all the information you need by using the search tool (see the link I gave above). Good luck and let us know if you have any more questions.

Layne
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic