Differences between Abstract class and interface? tccicomputercoaching.com
- June 19, 2019
- Posted by: Riddhi Dhandha
- Category: Java course at TCCI
What is Interface?
The interface is a blueprint that can be used to implement a class. The interface does not contain any concrete methods (methods that have code). All the methods of an interface are abstract methods.
An interface cannot be instantiate. However, classes that implement interfaces can be instantiated.
What Is Abstract Class?
A class which has the abstract keyword in its declaration is called abstract class. Abstract classes should have at least one abstract method., i.e., methods without a body. It can have multiple concrete methods.
Abstract classes allow you to create blueprints for concrete classes. But the inheriting class should implement the abstract method.
Abstract classes cannot be instantiated.
Let us see Differences between An interface and an Abstract class.
- Interfaces are used to achieve abstraction. Abstract classes offer default functionality for the subclasses.
- Everything defined inside the interface is assumed public modifier. Abstract Class can have an access modifier.
- Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.
- An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.
- A Java class can implement multiple interfaces but it can extend only one abstract class.
- The interface cannot contain data fields. the class can have data fields.
- An interface is abstract so that it can’t provide any code. An abstract class can give complete, default code which should be overridden.
- An interface can inherit multiple interfaces but cannot inherit a class. An abstract class can inherit a class and multiple interfaces.
- An interface cannot declare constructors or destructors. An abstract class can declare constructors and destructors.
- It can extend any number of interfaces. It can extend only one class or one abstract class at a time.
- In an abstract interface keyword, is optional for declaring a method as an abstract. In an abstract class, the abstract keyword is compulsory for declaring a method as an abstract.
- An interface can have only public abstract methods. An abstract class has protected and public abstract methods.
2. abstract class
abstract class name
To learn more about Java Programming Languages You can join at TCCI Computer Coaching Institute in Ahmedabad.
Call us @ 9825618292
Visit us @ www.tccicomputercoaching.com