Professional Documents
Culture Documents
Selenium With Java7-Interface
Selenium With Java7-Interface
There can be only abstract methods in the java interface not method body.
o To achieve abstraction.
o By interface, we can support the functionality of multiple inheritance.
o It can be used to achieve loose coupling.
A class extends another class, an interface extends another interface but a class
implements an interface.
Example
Printable interface has only one method, its implementation is provided in the
A class.
interface printable
{
void printABC();
}
Example: Drawable
TestInterface1.java
WebDriver d; //driver =d
d.get( )
//In real scenario, object is provided by method e.g. getDrawable()
d.draw( );
}
}
Example: Bank
TestInterface2.java
interface Bank
{
float rateOfInterest( );
}
class SBI implements Bank
{
System.out.println("ROI: "+bObject.rateOfInterest());
}
}
Multiple inheritance by interface
If a class implements multiple interfaces, or an interface extends multiple
interfaces i.e. known as multiple inheritance.
interface Printable
{
void print();
}
interface Showable
{
void show();
}
import selenium.WebDriver;
Class selenium
{
public static void main(String args[])
{
WebDriver driver = new ieDriver( );
}
Extends – class to class
Interface ---package –classes---- import