Regarding abstract and interface

When sholud i go for abstract class and when sholud i go for interace and which one will prefer when we are doing project...?
[132 byte] By [mega.chiranjeevia] at [2007-11-27 5:12:43]
# 1
Can you any one reply back to topic.
mega.chiranjeevia at 2007-7-12 10:33:52 > top of Java-index,Core,Core APIs...
# 2

A class implementing an interface must implement all of the methods defined in the interface,

while a class extending an abstract class need not implement any of the methods defined in the abstract class.

Additionally, a class extending an abstract class can implement an infinite number of it's own methods.

Nitin_Guptaa at 2007-7-12 10:33:52 > top of Java-index,Core,Core APIs...
# 3

The basic purpose behind interfaces and abstract classes is that the class architect or programmers wants all the derived classes to implement the methods it has defined.. So whenever the abstract class is extended or an interface is implemented, all of its methods need to be overridden to avoid errors.

The most common question is"What is the difference between abstract classes and interfaces?"

The answer is : suppose you have many classes having some same methods, put the common functions/methods in abstract class or interface, but what to use in a particular case interface or abstract class.

Commonly interfaces are used, which expose a class's functionality to the out side world. But if you think that the classes share a common functionality, then put that common functionality in the abstract class.

So it means that you can define/implement a method in abstract class but you can not do so in interfaces.

all the variables defined in interfaces are public static and final implicitly so you do not need to write public static final by you self.

some links for more help:

http://forum.java.sun.com/thread.jspa?threadID=641243&messageID=3773498

If you have time read the following article, its great, else go to the end of the page and see the diff. b/w both..

http://jdj.sys-con.com/read/37695.htm

ali_hammada at 2007-7-12 10:33:52 > top of Java-index,Core,Core APIs...
# 4

The basic purpose behind interfaces and abstract classes is that the class architect or programmers wants all the derived classes to implement the methods it has defined.. So whenever the abstract class is extended or an interface is implemented, all of its methods need to be overridden to avoid errors.

The most common question is"What is the difference between abstract classes and interfaces?"

The answer is : suppose you have many classes having some same methods, put the common functions/methods in abstract class or interface, but what to use in a particular case interface or abstract class.

Commonly interfaces are used, which expose a class's functionality to the out side world. But if you think that the classes share a common functionality, then put that common functionality in the abstract class.

So it means that you can define/implement a method in abstract class but you can not do so in interfaces.

all the variables defined in interfaces are public static and final implicitly so you do not need to write public static final by you self.

some links for more help:

http://forum.java.sun.com/thread.jspa?threadID=641243&messageID=3773498

If you have time read the following article, its great, else go to the end of the page and see the diff. b/w both..

http://jdj.sys-con.com/read/37695.htm

-I hope the question has been answered-

Cheers;

Ali Hammad

ali_hammada at 2007-7-12 10:33:52 > top of Java-index,Core,Core APIs...
# 5
hi,plz go through the following link, u may get some useful information. http://www.sap-img.com/java/when-we-go-for-abstract-and-interface.htm
sriramaa at 2007-7-12 10:33:52 > top of Java-index,Core,Core APIs...