aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the difference between interface and abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the difference between interface and abstract class" Watch "what is the difference between interface and abstract class" New topic
Author

what is the difference between interface and abstract class

Stephen Lee
Ranch Hand

Joined: Dec 11, 2001
Posts: 74
They seem to be very similar, what is their difference?
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
let me think...
1)
interface, all methods are abstract.
abstract, you can have real method with implement.

People!! keep the list going!
I will keep posting if i remember more, hehhee.

[This message has been edited by FEI NG (edited December 11, 2001).]
Sravanthi Dasari
Greenhorn

Joined: Dec 11, 2001
Posts: 6
Hi Stephen,
A frequent doubt this one...
See if these reasons satisfy u..I couldnt think of any more for the time being....
for one thing...Interfaces are not allowed constructors but abstract classes are.Abstract classes can be given constructors which of course cannot be called directly since the class is abstract.When u instantiate the class that extends this abstract class,u can place an explicit call to super or the system calls it automatically in the hierarchy.
And another... abstract classes can have non-abstract methods also but an interface's all methods are implicitly abstract.

All variables of an interface all implicitly static final ,not so for an abstract class.
so simply put an Interface could be called a pure abstract class.
Simeon Shi
Ranch Hand

Joined: Dec 09, 2001
Posts: 35
i also have such kind of questions...
we have the "pure" abstract class--interface,then what's the reason for the abstract class being exist?
more...
why Java uses the single inheritance rather than the multi-inheritance mechanism which is used in C++ ? any advantages?
thinking....
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
Originally posted by simeon shi:
i also have such kind of questions...
we have the "pure" abstract class--interface,then what's the reason for the abstract class being exist?
more...
why Java uses the single inheritance rather than the multi-inheritance mechanism which is used in C++ ? any advantages?
thinking....

Classes are to support inheritence, Interfaces are implemented, Abstract classes can be extended and there abstract methods can be implemented.
Multi inheritance has Diamond shape problem regarding instance variables so if you do not declare instance variable as virtual you will end up having duplicate copies of member varible(I do not remember whether compiler forces it or not, actually compiler should force it.) If a class has been defined and it does not have virtual member variable then you can not enjoy multi inheritance.
HTH
CMIW

------------------
Regards
Ravish
[This message has been edited by ravish kumar (edited December 12, 2001).]


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
 
 
subject: what is the difference between interface and abstract class