File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract, Interfaces!

 
Anuja
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is Abstract kayword and Interfaces?
Would you please explained by an example?
Thanks a lot!
Regards,
Anuja
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Is an Interface?
 
Anuja
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
I appreciate your response.
Thanks a lot,
Regards,
Anuja
Originally posted by Anuja:
What is Abstract kayword and Interfaces?
Would you please explained by an example?
Thanks a lot!
Regards,
Anuja

 
srikishore koduri
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
the significant diffrence b/w abstract and interface is:
abstract class can have non abstract methods i.e. implemented methods also where as interfaces cann't have.
 
Venu G Askani
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract keyword is used to define a method as abstract or any class as abstract. A class is defined as abstract when it contains at least one method as abstract. It can contain the other methods that are not abstract. Well interfaces are classes which have all the methods that are not implemented. These came to arise because of the indirect implementation of Multiple Inheritance. The interfaces are designed to implement multiple inheritance. And the abstract classes can be extended by a wide variety of classes that implement that abstract methods.
Hope i explained the query correctly..
Bye
Venu
Originally posted by Anuja:
What is Abstract keyword and Interfaces?
Would you please explained by an example?
Thanks a lot!
Regards,
Anuja

 
Venu G Askani
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anuja,
I suppose the difference in the definition is due to the constraint in java of multiple inheritance. The multiple inheritance is done or rather achieved in java by the use of interfaces. In this way you can do multiple inheritance.
Bye
Venu
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Hi,
I just want to add that an abstract class need NOT contain an abstract method. All the methods in a class can be provided implementation and the class can still be abstract by specifying so.
Vani
 
Sachin Kombrabail
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As per my understanding
1. Both interfaces & abstract classes cannot be explicitly instantiated.
2. Even a single method being defined abstract makes the class abstract.
3. All the methods of an interface HAVE to implemented by the implementor.
4. Unlike a interface, a method of an abstract class can have default implementation.
5. A class can extend a single parent but can implement multiple interfaces.
6. The only thing that a class can inherit from an interface is the message signatures. From an abstract class you can inherit the default implementations.
For a good example take any listener say the WindowListener which is an interface. If you want to implement it you have to implement all the 7 methods that are there in the interface. Now look at the WindowAdapter. This is an abstract class which has implemented all the methods of the WindowListener but all the implementations are empty. To make use of this combination you will have to extend the WindowAdapter and only code that method you want.
 
Anuja
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Tony,Srikishore,Venu,Kadur,Sachin

Thanks a bunch !!!
Thank Again all of your response

Regards,
Anuja
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic