• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class and interface.

 
SHINU .R SHINU .R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ANY BODY CAN TELL WHAT IS THE EXACT DIFFERENCE BETWEEN ABSTRACT CLASS AND INTERFACE???
wHERE THESE ARE USE??WHERE NOT USED
[ September 02, 2005: Message edited by: Barry Gaunt ]
 
Swapna James
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Abstract classes and interfaces cannot be instantiated

Abstract class can contain non abstract methods while interface cannot contain any non abstract methods

Interface should contain all public members while abstract classes can have public, protected, default and private members.

These are the major differences.

Swapna
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shinu R, please read our JavaRanch Naming Policy and change your displayed name to comply. We need a displayed name in the format <first name><space><family name>, preferably your real name.

And please do not post in capital letters, there is no need to draw attention to yourself in this impolite way.
Thanks,
-Barry

(NR)
[ September 02, 2005: Message edited by: Barry Gaunt ]
 
kailash mehra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface cann't be protected or private but it can be default or public .
abstract class can have all access modifiers.
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes are usually the Parent classes Ex. class Animal. Then you probably would have a subclass Canine Extends Animal. Then after that you may have a class Dog Extends Canine Implements Pet. The Pet Interface which you can use to be implemented on all Animal subclasses regardless of be them being class Bird for example that would implement the Pet Interface.

Now imagine you have an Animal class which is not abstract, then you may be able to create a new Animal object. But what animal could this be? So it would be better to have an abstract class Animal, which can be extended but not instantiated.
[ September 03, 2005: Message edited by: Megs Maquito ]
 
kailash mehra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi interface can not be private and default but abstract class can have all access modifier's
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic