Skip to main content

Difference between Abstract Class and Interface

Difference between Abstract Class and Interface

Difference between abstract class and interface ?

Abstract Class:-

1) Can have abstract and non-abstract method both.
2) One class can extend at most one class.
3) can declare non abstract method and also can define body for it.

1) can have only abstract method.
2) One class can implement multiple interfaces.
3) can't delare body to a method.

Please look below example for more understanding:-

package Basics;

public abstract class Animal {

 int  head;
 //no body (unimplemented function need to override in child class as a
 abstract void setLegs();
 //having body
 //may override or may not
 void setHead()

package Basics;

// can have only methods and by default all are abstract need to be override
//by implementing class, unlike abstract no method can havedefinition
public interface Pet {

 void tellWhereAreYouFrom(String place);
 String tellYourWeight(String weight);

package Basics;

// can extend one class but can implement multiple interface
public class Dog extends Animal implements Pet{

 //must override all abstract methods from Parent class
 void setLegs() {
  System.out.println("i have four legs");

 //must override all methods from an interface
 public void tellWhereAreYouFrom(String place) {
  System.out.println("My place is"+place);

 public String tellYourWeight(String weight) {
  return weight;




Popular posts from this blog

Topics to Start - preparing for Data Structures and Algorithms

Learn in a different way :- Strings stacks and queues heaps searching hash table sorting recursion dynamic programming greedy algorithms graphs tree Binary Search Tree Linked List Array Parallel programming and concurrency design problems system design availability and scalability  Below topics are good to have object oriented programming language details ( java , python) object oriented design tools ( bash , git , maven , jira , jenkins , docker , kubernetes) database

Best LeetCode Lists for Interviews

Here is a list of some of the best questions asked in interviews:-  Must do 75 Must do 60 Must do medium:- Must do Easy:- Graph:-  Dynamic Programming:-  FaceBook interviews:-  Amazon Interviews:-  Google Interviews:-