By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,028 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,028 IT Pros & Developers. It's quick & easy.

Difference between Interfaces and Abstract Class

P: 38
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.
Jan 2 '16 #1

✓ answered by Vikas Rana

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

Share this Question
Share on Google+
3 Replies


P: 3
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
Jan 2 '16 #2

P: 18
Hey,
Abstract class:
-abstract class can extend only one class or one abstract class at a time
-abstract class can extend from a class or from an abstract class
-In abstract class keyword ‘abstract’ is mandatory to declare a method as an abstract
-abstract class can have static, final or static final variable with any access specifier
Interfaces:
-interface can extend any number of interfaces at a time
-interface can extend only from an interface
-interface can have only abstract methods
-Interface can have only public abstract methods i.e. by default
interface can have only static final (constant) variable i.e. by default
Jan 12 '16 #3

P: 29
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:

Expand|Select|Wrap|Line Numbers
  1. public abstract class Shape{
  2. public abstract void draw();
  3. }
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. public interface Drawable{
  2. void draw();
  3. }
  4.  
May 29 '20 #4

Post your reply

Sign in to post your reply or Sign up for a free account.