Difference between Interfaces and Abstract Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aswal
    New Member
    • Aug 2013
    • 38

    Difference between Interfaces and Abstract Class

    Both of them provides abstraction and we have to give their implementation in their child classes so what's exactly is the difference between them and also please suggest me some scenario where i can use them.
    Last edited by zmbd; Jan 2 '16, 06:19 PM. Reason: [z{Please see your Bytes.com Inbox}]
  • Vikas Rana
    New Member
    • Jan 2016
    • 3

    #2
    Difference between Interfaces and Abstract Classes

    When we declare any method inside the Interface it is implicitly abstract in other words we can say that you cannot give a definition of a method inside the interface because it would be an error BUT this is not the case with Abstract Classes, it can and cannot contain abstract methods.
    Note - There should be at least one abstract method in an Abstract Class

    Comment

    • Sherin
      New Member
      • Jan 2020
      • 77

      #3
      Abstract Class

      An abstract class may contain concrete method.
      To use an abstract class, you need to inherit it. Provide body to (override) the abstract methods if there are any.
      Members of an abstract class can be public, private, protected or default.

      Example:

      Code:
      public abstract class Shape{
      public abstract void draw();
      }
      Interface

      All the methods of an interface are abstract.
      To use an interface you need to implement the interface and provide body to (override) all the abstract methods of it.
      All the members of the interface are public by default.

      Example:
      Code:
      public interface Drawable{
      void draw();
      }

      Comment

      Working...