Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on Difference between interface and abstract class? are they both same within the OOPS forums, part of the Software Development category; Difference between interface and abstract class? are they both same...
|
|||||||
|
|||
|
Difference between interface and abstract class? are they both same
|
| The Following User Says Thank You to mahesh9920 For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: Difference between interface and abstract class? are they both same
Hi,
An interface provides only the signatures of methods that any class implementing that interface will implement. An abstract class provides implementation of the common functionalities present and declares methods specific to base classes as abstract. Regards, Sahil. --Smile, it makes people wonder what you are thinking.
|
| The Following User Says Thank You to SahilKabra For This Useful Post: | ||
|
|||
|
Quote:
An abstract class provides signatures and also the functionality of the signature both are override it |
| The Following User Says Thank You to sarathi trichy For This Useful Post: | ||
|
|||
|
Interface :
1) Interface is pure contract. Any class implementing interface must override all methods provided by that interface. 2) There cant be function definition in interface. 3) We can not instantiate interface Abstract Class 1) Abstract class can contain function body. 2) Abstract class must contain at least one abstract method |
| The Following 4 Users Say Thank You to vpaithankar For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
INTERFACE:
- it contains only unimplemented methods - may or may not be used. - if you used interface all methods must be implemented. - variable must be abstract and final - methods take abstract as default. - interface must be public. - one class can implement number of interfaces. - interfaces properties are included with implements key word. ABSTRACT - it contains both implented and unimplemented method. - it allows both abstract and non abstract methods. - it must be used if u declare it otherwise compiler gives an error. - the abstract class must be contain at least one abstract method. - it may be public or protected. - only one class can extend abstract class. - abstract properties are included with extends keyword. |
| The Following 3 Users Say Thank You to rahulvegi For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
hi
interface--It is set of abstract methods.It only has a definition of methods which include name of method,its signature.here none of the methods are implemented. abstract class--A class is a abstract class when there is even one abstract method while other methods have body. |
| The Following User Says Thank You to poo_roh For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
Abstract class cannot Instainted or Object cann't be created from Abstract class.
It contains both implemented and non Implemented Methods. Interface contains abstract methods means non implemented method. |
| The Following User Says Thank You to Ask2gk For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
Abstract class and interfaces are completely different.
1) In an abstract class, you may also have some concrete methods( fully implemented. It can have all its methods as concrete, yet be declared as abstract) , but in an interface, all the methods ought to be abstract. 2)Abstarct class can never be instantiated, but you can indirectly instantiate an interface by instantiating the class which implements it and then use the its methods. |
|
|||
|
Re: Difference between interface and abstract class? are they both same
1)Abstract class is a collection of abstract methods and concrete methods or only abstract methods or only concrete methods
Interface is a collection of only abstract methods 2)the members of the abstract class are public(default),protected,static the members of interface are implicitly public 3)A class can inherit one or more interfaces but a class can inherit only one abstarct class 4)abstract class can add more functiuonality without destroying the child classes in an interface..creation of additional functions will have an effect on its child class due to necessary implementation of interface methods in child class |
|
|||
|
Quote:
Abstract Class 1.Abastract class can have abstract and non abstract methods. 2. Abstract class is basically for inheritance purpose. 3. Abstract class can have method implementation also. 4. Variables can be declared in abstract class. Interface 1. Interfaces have all methods abstract. 2. No access modifiers allowed in methods declared in interface. 3. No implementation of methods as all methods are abstract. 4. variables can not be declared in interfaces only methods and properties |
|
|||
|
Re: Difference between interface and abstract class? are they both same
Thanks to all, Very clearly every one tries to explain the difference between interface and abstract class.
|
|
|||
|
Re: Difference between interface and abstract class? are they both same
no they aren't...
the reason is that An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class. |
|
|||
|
Re: Difference between interface and abstract class? are they both same
Hi,
Abstract class may declare concrete methods also. One class extends only one abstract class. interface should declare only abstract methods. One class implement one or more interfaces. implementation of abstract methods in any class are declared as public implicitly. FYI SHASHI |
| The Following User Says Thank You to sjava.438 For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
1. Abstract classes can have concrete method while interfaces have no methods implemented.
2. Interface do not come in inheriting chain, while abstract class come in inheritance. 3. Abstract classes are faster than interfaces. 4. By default, all members in Interface is Public whereas members in Abstract class may have different. |
| The Following User Says Thank You to Sushma Mosali For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
Re: Difference between interface and abstract class? are they both same
There are some diff b/w abstract and interface. 1>all the member in interface are abstract,without use a abstract keywoard. 2>in the abstract class use abstract and non abstract.if in the abstract class u use not abstract then u will declare method mody. |
| The Following User Says Thank You to Shiv Ratan Kumar For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
interface and abstract are both implemented internally inheritence concept
|
| The Following User Says Thank You to pvram For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
interface and abstract are both implemented internally inheritence concept.
in interface implement the inheritence between unrelated class and abstract implement inheritence between related classe. one interface extends many interfaces at a time but an class extends one abstract class at time |
| The Following User Says Thank You to pvram For This Useful Post: | ||
|
|||
|
Re: Difference between interface and abstract class? are they both same
Abstract Class vs. Interface
• An abstract class may contain complete or incomplete methods. Interfaces can contain only the signature of a method but no body. Thus an abstract class can implement methods but an interface can not implement methods. • An abstract class can contain fields, constructors, or destructors and implement properties. An interface can not contain fields, constructors, or destructors and it has only the property's signature but no implementation. • An abstract class cannot support multiple inheritances, but an interface can support multiple inheritance. Thus a class may inherit several interfaces but only one abstract class. • A class implementing an interface has to implement all the methods of the interface, but the same is not required in the case of an abstract Class. • Various access modifiers such as abstract, protected, internal, public, virtual, etc. are useful in abstract Classes but not in interfaces. • Abstract classes are faster than interfaces. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Real time example for abstract class and interface | Geek_Guest | Java | 4 | 04-15-2009 08:20 AM |
| difference between abstract class and interface | manipalreddy.s | Java | 12 | 10-25-2007 07:06 AM |
| Is there any benefit to extend both Interface and abstract class | Geek_Guest | Java | 1 | 06-08-2007 01:54 PM |
| Confusion with ABSTRACT and INTERFACE | Geek_Guest | Java | 2 | 05-07-2007 04:38 AM |
| Difference between Remote & Serializable interface | Geek_Guest | Java | 1 | 04-02-2007 11:15 AM |