Difference between abstract class and interface

Whats In Name

Whats In Name

@whats-in-name-KdgM7o Oct 26, 2024
Lets discuss differences between an interface and an abstract class in Java,to start with-

An abstract class can have non-abstract method but an interface cannot.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Vishal Sharma

    Vishal Sharma

    @vishal-pysGmK May 27, 2013

    interface uses abstract classes
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn May 27, 2013

    abstract class :
    1. can have all the methods unimplemented (abstract) like interfaces (useless why not use interfaces)
    2. Generally have some implemented and some of the unimplemented methods so child class can use unimplemented as they want and already implemented methods in abstract class they already present while extending.

    Interfaces:
    1. Main purpose of using interfaces is a contract, between client and developer that what kind of method a class should have. Client does know what an object could do but not the implementation. It's job of developer.
    2.Since interfaces can point to any object of class which have implemented it. In real programming developer always makes reference to interface not the concrete class name.
    Actual purpose of interfaces to provide a structure of a project.

    Rest of syntax tricks, you can Google and exercise it.😀