Page 1 of 2 12 LastLast
Results 1 to 20 of 31

Thread: Difference between interface and abstract class? are they both same

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    15

    Question Difference between interface and abstract class? are they both same

    Difference between interface and abstract class? are they both same


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    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.


  3. #3
    Contributing Member
    Join Date
    Oct 2007
    Answers
    88

    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


  4. #4
    Junior Member
    Join Date
    Dec 2007
    Answers
    2

    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


  5. #5
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    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.


  6. #6
    Junior Member
    Join Date
    May 2008
    Answers
    7

    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.


  7. #7
    Junior Member
    Join Date
    May 2008
    Answers
    2

    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.


  8. #8
    Junior Member
    Join Date
    Jul 2007
    Answers
    3

    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.


  9. #9
    Junior Member
    Join Date
    May 2008
    Answers
    1

    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


  10. #10
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: Difference between interface and abstract class? are they both same

    What is the difference between in-line and macro function in c, c++.


  11. #11
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    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


  12. #12
    Expert Member
    Join Date
    Dec 2007
    Answers
    138

    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.


  13. #13
    Junior Member
    Join Date
    Aug 2008
    Answers
    6

    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.


  14. #14
    Junior Member
    Join Date
    Aug 2008
    Answers
    15

    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


  15. #15
    Expert Member
    Join Date
    Jun 2007
    Answers
    260

    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.


  16. #16

    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.


  17. #17
    Junior Member
    Join Date
    Nov 2008
    Answers
    3

    Re: Difference between interface and abstract class? are they both same

    interface and abstract are both implemented internally inheritence concept


  18. #18
    Junior Member
    Join Date
    Nov 2008
    Answers
    3

    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


  19. #19
    Junior Member
    Join Date
    Jan 2009
    Answers
    2

    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.


  20. #20
    Junior Member
    Join Date
    Jan 2009
    Answers
    2

    Re: Difference between interface and abstract class? are they both same

    what is the member hide?


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact