• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the difference between interface and abstract class

 
Stephen Lee
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They seem to be very similar, what is their difference?
 
Fei Ng
Ranch Hand
Posts: 1244
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5382
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic