Geeks Talk

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.

Difference between interface and abstract class? are they both same

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...

Go Back   Geeks Talk > Software Development > OOPS
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

OOPS Object-Oriented Programming Concepts

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-01-2007
Junior Member
 
Join Date: Jul 2007
Location: Mumbai
Posts: 17
Thanks: 1
Thanked 6 Times in 5 Posts
mahesh9920 is on a distinguished road
Question Difference between interface and abstract class? are they both same

Difference between interface and abstract class? are they both same
Reply With Quote
The Following User Says Thank You to mahesh9920 For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 10-03-2007
Contributing Member
 
Join Date: Sep 2006
Location: India
Posts: 39
Thanks: 2
Thanked 11 Times in 10 Posts
SahilKabra is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to SahilKabra For This Useful Post:
  #3 (permalink)  
Old 10-29-2007
Contributing Member
 
Join Date: Oct 2007
Location: trichy
Posts: 92
Thanks: 2
Thanked 13 Times in 9 Posts
sarathi trichy is on a distinguished road
Smile Re: Difference between interface and abstract class? are they both same

Quote:
Originally Posted by mahesh9920 View Post
Difference between interface and abstract class? are they both same
An interface provides only the signatures of methods that any class implementing that interface will implement.
An abstract class provides signatures and also the functionality of the signature both are override it
Reply With Quote
The Following User Says Thank You to sarathi trichy For This Useful Post:
  #4 (permalink)  
Old 12-12-2007
Junior Member
 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 4 Times in 1 Post
vpaithankar is on a distinguished road
Thumbs up Re: Difference between interface and abstract class? are they both same

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
Reply With Quote
The Following 4 Users Say Thank You to vpaithankar For This Useful Post:
  #5 (permalink)  
Old 12-25-2007
Contributing Member
 
Join Date: Nov 2007
Location: bangalore
Posts: 54
Thanks: 6
Thanked 6 Times in 4 Posts
rahulvegi is on a distinguished road
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.
Reply With Quote
The Following 3 Users Say Thank You to rahulvegi For This Useful Post:
  #6 (permalink)  
Old 05-28-2008
Junior Member
 
Join Date: May 2008
Location: mumbai
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
poo_roh is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to poo_roh For This Useful Post:
  #7 (permalink)  
Old 05-29-2008
Junior Member
 
Join Date: May 2008
Location: Chandigarh
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Ask2gk is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to Ask2gk For This Useful Post:
  #8 (permalink)  
Old 06-03-2008
Junior Member
 
Join Date: Jul 2007
Location: Gurgaon
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
vaneet is on a distinguished road
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.
Reply With Quote
  #9 (permalink)  
Old 06-09-2008
Junior Member
 
Join Date: May 2008
Location: India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
jkreddy.peram is on a distinguished road
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
Reply With Quote
  #10 (permalink)  
Old 06-10-2008
Junior Member
 
Join Date: Jun 2008
Location: Banglore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kanvi17 is on a distinguished road
Re: Difference between interface and abstract class? are they both same

What is the difference between in-line and macro function in c, c++.
Reply With Quote
  #11 (permalink)  
Old 06-19-2008
Junior Member
 
Join Date: Jun 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ch.vikas is on a distinguished road
Post Re: Difference between interface and abstract class? are they both same

Quote:
Originally Posted by mahesh9920 View Post
Difference between interface and abstract class? are they both same
No
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
Reply With Quote
  #12 (permalink)  
Old 06-20-2008
Expert Member
 
Join Date: Dec 2007
Location: Pune
Posts: 139
Thanks: 0
Thanked 7 Times in 7 Posts
peeyush_jain is on a distinguished road
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.
Reply With Quote
  #13 (permalink)  
Old 08-12-2008
Junior Member
 
Join Date: Aug 2008
Location: chandigarh
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
vini.rana is on a distinguished road
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.
Reply With Quote
  #14 (permalink)  
Old 08-21-2008
Junior Member
 
Join Date: Aug 2008
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
sjava.438 is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to sjava.438 For This Useful Post:
  #15 (permalink)  
Old 08-22-2008
Expert Member
 
Join Date: Jun 2007
Location: Australia
Posts: 260
Thanks: 7
Thanked 15 Times in 15 Posts
Sushma Mosali is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to Sushma Mosali For This Useful Post:
  #16 (permalink)  
Old 10-28-2008
Junior Member
 
Join Date: Oct 2008
Location: Bangalore
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Shiv Ratan Kumar is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to Shiv Ratan Kumar For This Useful Post:
  #17 (permalink)  
Old 11-19-2008
Junior Member
 
Join Date: Nov 2008
Location: chennai
Posts: 3
Thanks: 0
Thanked 2 Times in 2 Posts
pvram is on a distinguished road
Re: Difference between interface and abstract class? are they both same

interface and abstract are both implemented internally inheritence concept
Reply With Quote
The Following User Says Thank You to pvram For This Useful Post:
  #18 (permalink)  
Old 11-19-2008
Junior Member
 
Join Date: Nov 2008
Location: chennai
Posts: 3
Thanks: 0
Thanked 2 Times in 2 Posts
pvram is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to pvram For This Useful Post:
  #19 (permalink)  
Old 01-08-2009
Junior Member
 
Join Date: Jan 2009
Location: hyderabad
Posts: 7
Thanks: 5
Thanked 0 Times in 0 Posts
srisatish9900 is on a distinguished road
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.
Reply With Quote
  #20 (permalink)  
Old 01-08-2009
Junior Member
 
Join Date: Jan 2009
Location: hyderabad
Posts: 7
Thanks: 5
Thanked 0 Times in 0 Posts
srisatish9900 is on a distinguished road
Re: Difference between interface and abstract class? are they both same

what is the member hide?
Reply With Quote
Reply

  Geeks Talk > Software Development > OOPS

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 04:31 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved