• Post Reply Bookmark Topic Watch Topic
  • New Topic

abstract Vs interface  RSS feed

 
SaiRam NageshKumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear remote java friends,
I just wank to know the clear-cut idea about the exact differences between abstract and interface in declaring and the imlementation as well.
Plase make a comprehencive discussion regarding this.
I know something like :
1. Classes extend abstract class whereas classes implements interface.
2. Instance variables are constants(static) and public in interface whereas not in abstract.
3. Abstract class may or may not have the abstract methods but all the methods in the interface are abstract. As well as if any class has abstract methods must be declared as abstract
4. Interface is public by default but abstract is not.
5. Multiple inheritance is possible with the abstract but single with the interface.
6. Abstract classes can not be instantiated, ofcourse interface is the same. ******
If any thing more specific please let me know to gain more about those.
Thanks in advance to all!
Sai Ram.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5.Multiple inheritance is possible with the abstract but single with the interface.
I am not clear of this ..any explanations please....
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre> We can declare any method inside an interface as abstract but the consequences...?


I hope the ranch hands will explain
<pre>
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain 5 for me.I couldn't able to understand what they are trying to say.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they meant to say it the other way around in 5. You can only extend one other class in Java. But you can implement many interfaces.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't wake the Zombies.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sairam,
Great yaar, you are not satisfied with what you have. and you want better yourself. Good.

Here we go...
Abstract class means : "A class which is functionally incomplete". -we can't say "A class which has at least one abstract class(Absolutely wrong)"
Why : take example of java.awt.Component
you won't find any abstract classes inside it. Then why its declared abstract.??? Because it is functionally incomplete.

where as Interface purpose is to act like bridge between two communication parties.

Ex: Webservices WSDL file.
in RMI interface declared by Service provider. with help of interface service provider can expose only necessary methods invokable by client.

Lets Rock

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!