This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Interfaces Vs Abstract Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces Vs Abstract Classes" Watch "Interfaces Vs Abstract Classes" New topic
Author

Interfaces Vs Abstract Classes

Prashanth Lingala
Ranch Hand

Joined: Nov 13, 2004
Posts: 66
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???


Have A Nice Day !!!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces Vs Abstract Classes
 
Similar Threads
abstract class & interface
Need help on deadly diamond of death..
Abstract Classes Vs Interfaces
Abstract, Interfaces!
abstract class