English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Here is the specific homework question: "Compare and contrast abstract classes and interfaces. Why would you use an abstract class? Why would you use an interface?" My problem with this, is that I completely don't understand the concepts enough to compare or contrast them. I am looking for a concise answer but detail enough to understand this better.

Currently, all I know about abstract classes is that you make an abstract class to provide an appropriate superclass from which other classes can inherit and thus share a common design.

And all I know about interfaces is that they are useful for assigning common functionality to possibly unrelated classes so that objects of those unrelated classes can be processed polymorphically.

But I don't at all understand how these two things relate in a practical useful sense.

Thank you.

2007-03-26 06:12:54 · 2 answers · asked by prodaugh-internet 3 in Computers & Internet Programming & Design

2 answers

An interface specifies the a set of methods and their signatures that classes implementing that interface must follow. It does not contain any implementation. An abstract class does much the same thing, but it can have a default implementation associated with some methods, and force other (abstract) methods to be implemented by the class that subclasses the abstract method. The implementation can also reimplement and override any of the default implementations provided in the abstract class.

Because Java does not support multiple inheritance, you can only declare a class as extending a single other class (including abstract classes), whereas a class can implement any number of interfaces.

I hope this helps.

2007-03-26 07:21:50 · answer #1 · answered by Phaedrus 3 · 1 0

An summary type is a form the has unimplemented approaches that should be carried out in a derived type. summary instructions won't be able to be instantiated. An interface isn't a form: "interface type" does no longer mean some thing. An interface specifies a series of approaches a form utilising it -- called imposing in Java -- will outline. An interface is a contract between the style and the shopper specifying a minimum set of approaches it implements. for extra information, Google is your chum. HTH

2016-12-02 20:30:55 · answer #2 · answered by luci 4 · 0 0

fedest.com, questions and answers