What is interface? Explain difference between abstract class and interface with the help of example. Write a java program to demonstrate use of interface.
In computer science, an interface is a specification of a set of methods that a class should implement. An interface defines a contract for a class, specifying a set of methods that a class must implement in order for it to be considered as conforming to the interface. In other words, an interface defines the behavior that a class must exhibit in order to be considered as fulfilling the interface contract.
Interfaces are typically used to define common functionality that can be shared across multiple classes. This allows for the implementation of polymorphism, which means that objects of different classes can be used interchangeably as long as they implement the same interface.
Interfaces are typically defined using an interface keyword in languages such as Java and C#, or using a protocol keyword in Swift, or in other languages like C++ , C, Python, etc. They often uses "abstract class" as the way to implement interface.
Here is an example of an interface in Java:
interface Shape {
double getArea();
}
In this example, any class that implements the Shape interface must provide an implementation for the getArea() method.
An interface also serves as a way to define a contract between different components _____ _____ ______ _____ __________ ________ ________ ______ ________ __________.
__________ ___ ______ _________ ____ ______ ___ ___ _______.
_______ _______ ___ _____ ____ _______ _________ ___.
________ ___ _________ ____ ____ ____ ________ _________.
______ ________ _________ ______ _______ __________ ____.
___ _______ ________ ___ ________ _________ _____.
______ __________ ____ _________ _______ _____ ________ ________ ___ ________.
___ _______ ____ _______ ____ __________ ________ ____.
___ ______ ____ ______ ___.
_______ ________ __________ _______ ________ ___ _____ __________ _______ _______.
___ __________ _________ ______ _________ _________ ____ _________.
____ ____ ______ ___ _____ ________ _____ _______.
__________ _______ _____ ___ ____ ______ _____.
__________ _________ _________ ________ __________ ____ ________ _______.
___ _______ _____ ________ _______ _______ _______ _______ _____.
__________ ____ ____ _________ _______ _________ _________ ___ __________ _________.
_______ _________ __________ ___ ________ _______ _______.
____ _______ ______ _____ _____ ______ ____ _____ _________.
_________ _________ _________ ____ ___ _____ _________ ______ ___ ____ _______ ______.
_______ ______ ________ __________ ______ ___ __________ _____ _____ __________.
_______ __________ ________ _________ _____.
__________ _______ __________ ___ _________ _____ ______ ________.
____ _____ ______ ____ _______ ____ _______ _________ ____.
______ _______ __________ _________ ________.
_______ ____ ____ _________ _______ __________ ________ ______.
___ __________ ________ _____ ________ ______ ________ _______ __________.
______ _______ _________ ____ ___ ______ _______ ____ _________ ____ _______ _______.
_______ ______ _________ ________ ______ __________ ____ ____ __________.
__________ ___ _______ ___ __________ _____ _________ _________ _________ ____ _______.
_____ _________ __________ _______ ________.
_________ _______ _________ _______ _____ _____ _________ ____ ______ _____ __________ __________.
________ ______ _______ ___ _______ ______ ___ __________ ______ ___.
__________ _____ __________ __________ ___ ______ ____ __________.
____ ___ __________ ________ _____ ____ _____ ___ ______ _____.
_______ ___ ____ ______ _____ ___.
______ ___ _______ ____ ______ __________ ______ ____ __________ ___ _________.
____ _____ ____ ________ ________.
________ ______ ________ _________ __________.
_____ _____ _________ ___ _________.
_____ _____ _________ ______ ____.
_______ _________ ____ _____ ________ ________ __________.
___ ______ ____ _____ ________ __________.
__________ ______ ___ ________ ______ __________ ________ ___ ______ ________ _________ ______.
_________ _________ __________ _______ _____ _____ ___ _____ _________ ___.
_________ _____ _______ ____ _______.
_______ ___ _______ _______ _______.
________ ________ _________ ____ __________ _________.
_________ ______ __________ __________ __________ _____ _______ ______ _________ ____ ___.
_______ ________ __________ ____ _____ ________ __________ ______.
_______ ________ ___ __________ __________ ________ _________ _______ _____ _________ ___ _________.
________ _________ ______ ___ ____ ________ ______ ______ __________ _________ __________ _________.
_____ __________ _____ _____ ________ _________ ______ _________ _________ ______.
_____ _______ _________ ______ __________ ____ ____ ______.
__________ ______ ___ ___ ___ ______ _______.
_____ _________ _________ _________ _________ _______ __________ _________ ________.
____ ______ ___ _____ ______ _____.
____ __________ _____ ____ _____ ____ ______ ____ ______ ____.
___ ________ _______ _____ _____ ________ _______ ________ ______ ______ ______ _______.
__________ ________ ______ ________ ____ ___ ______ ________ __________ __________.
_______ ____ _____ ________ __________ _________ __________ __________ ______ ______ ____ ___.
__________ ______ ________ ______ ____ ____ __________ ____.
___ _____ _____ _________ _____.
_________ __________ ___ ___ _______ __________ _________ ______ _______.
_____ _______ ________ _________ __________.
_____ _______ _______ ______ _________ ________ _____ ______.
____ _____ ____ ___ _______ ________ ___.
________ _______ ________ ________ _____ _____ __________.
_______ ________ ________ _____ _____ ____ _________ _____ ___ _____ ________ __________.
___ ________ _________ __________ ________ ____ _________.
_________ ____ __________ _____ _______ __________ ___ ______ ____ ______.
_________ ____ ____ ______ _______ ______ __________ ___.
_______ ____ __________ _____ _______ _____ ______.
_______ ____ ____ _________ _____ ____ _____ ______ _________ ______.
________ _____ _________ _______ _____ ____ __________ _______.
__________ __________ _________ _________ _______ ____ ________ ______ __________ ______.
___ __________ __________ ______ ____ __________ ____ ___ ________ ______.
______ ______ _______ ____ _________ _____ ____.
_____ __________ ______ ____ _______ _________ ___ _________.
______ __________ ____ _____ ______ _______ _____ _____ ___ __________.
___ _______ ___ ________ _________ _____ ___ ______.
_________ ________ ______ _______ _______ _________ ______ _________ __________ __________ ________.
_____ _______ _______ _____ ____ _______ __________ ___ __________ _____ _______ ______.
____ ____ ___ ______ _______ _______ ___.
______ ____ ___ _________ _______ ___ ______ ________.
_____ ____ __________ __________ ____ _______ _____.
______ _____ ____ _________ ____ ________ ________ _____.
__________ ________ ________ _________ ____.
________ ____ _______ ______ ______ _________ ____ ________ _________ ____ __________.
__________ ___ ______ _____ _________.
________ _____ _________ _______ ______ ___ ___ ___ __________.
__________ _______ __________ ______ ____ ___ ________ ______.
___ ________ _________ ________ _______ _________ ________ _______ __________ ________ ____ ____.
_____ __________ _________ _________ ___ _________ ___ ___.
_____ ___ ______ _____ ___ _________ ____ ________ ______ _______.
_______ _____ ___ _________ _____ _______ ________ ______ __________ _____.
__________ ____ __________ __________ ___ _________ ________ _____ ________ _________ ____ ______.
_______ ______ ________ _____ ______ ________ __________.
_____ ___ _______ ___ __________ __________ __________.
Get Full Answer on WhatsApp