Interfaces specify what a class must do.
It is the blueprint of the class.
It is used to achieve total abstraction.
We are using implements keyword for interface.
Basic statement we all know in Selenium is
WebDriver driver = new FirefoxDriver();
WebDriver itself is an Interface.
So we are initializing Firefox browser
using Selenium WebDriver.
It means we are creating a reference variable
of the interface and creating an Object.
So WebDriver is an Interface and
FirefoxDriver is a class.
It is used to achieve total abstraction.
Since java does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance .
It is also used to achieve loose coupling.
Interface Define a set of Characteristics and Behaviors
such as
Member Signature Only
No Implementation Details
Cannot be Instantiated
class Calculator(AdvancedArithmetic):
def divisorSum(self, n):
temp = []
for i in range(1, n+1):
if n%i == 0:
temp.append(i)
return sum(temp)
import { Component } from '@angular/core';
//Student interface
interface Student {
id: number;
name: string;
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
//Use of interface
students: Student[] = [
{id: 1, name: "Hardik"},
{id: 2, name: "Paresh"},
{id: 3, name: "Rakesh"},
]
}