Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Interfaces & Abstract classes

  Asked By: Pedro    Date: Jul 23    Category: Java    Views: 971
  

I am preparing for the SJCP exam, and want to verify a fact I found
in a book regarding Interfaces & Abstract classes.

I tried verifying it, by writing code and found otherwise so want to
confirm.

It mentions.. Abstract classes & interfaces are very similar in their
structure & implementation, however one differece is abstract class
does not have to have any methods, whereas an interface must have
atleast one empty method. --> I tried verifying this and found that
you can define and extend/implement either the abstract class or the
interface without any methods defined in them.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Liam Bouchard     Answered On: Jul 23

Infact we frequently do it. ie Categorize the global constants and
define them in various interface; then implement those interfaces
for the classes  that need the respective constants. In this way,
the interfaces  do not need to have any empty  method.

One possible difference is that a class  can extend only one abstract
classes whereas it can implement more than one interface. ie Java
doesnt support multiple inheritance (C++ does it by allowing a class
to extend more than one class)

 
Didn't find what you were looking for? Find more on Interfaces & Abstract classes Or get search suggestion and latest updates.




Tagged: