What is the purpose of garbage collection in Java, and when is it used? What is the purpose of garbage collection in Java, and when is it used? Abstract classes and interfaces are often compared and can sometimes do the same thing.
Abstract classes are base classes where the derived class must implement the methods of that abstract class. However, children of those 'derived' classes do not have to implement the methods of the original base class (abstract class). Furthermore, abstract classes form a 'is-a' relationship, meaning the derived classes "are" of type ...(abstract)...Ex: a Shapes abstract base class and a square derived class. A square is a shape.
Interfaces are different - they are simply guidelines and rules that must be followed by any and all classes that implement them. If you create a class that implements an interface, it must include all the methods in that interface. Then if you go to derive that class, you could overwrite the methods or leave them (as they will have already been implemented in the base class).
Interfaces are not a 'is-a' relationship. For example, you could have a Size interface. A square is not a size, but your square class must implement various size methods (volume, surface area).
In the long run, you will probably use interfaces more often if you are looking at polymorphism and attempting to force classes to include certain methods.
Answered by
ayisha
, an ibibo Master,
at
6:19 PM on June 01, 2008