In this Video we will discuss in detailed information about interfaces.
What is a JAVA Interface?
How to use the Interfaces?
What are the interface methods and variables?
Java Interface:
==============
An interface is a reference type in java.
It is similar to class , but it is a collection of abstract methods.
The class uses the interface by using the keyword implements.
Interface should not contain non-static methods
Methods : public abstract
variables: public static final
A class can implement multiple interfaces.
A class cannot extend more then one class.
public class HelloWorld implements Collection
{
public abstract void add()
{
}
public void addAll()
{
}
}
public interface Collection
{
public abstract void add();
public void addAll();
public static abstract void delete();
public void deleteAll()//not valid
{
}
}
Collection Interface :
5 methods
List Interface :
4 methods
public interface Collection{
5 abstract
}
public interface List extends Collection{
4 abstract
}
public class ArrayList implements List
{
5+4 = 9 methods provide implementation
}
Selenium WebDriver:
-------------------------
WebDriver driver = new ChromeDriver();
ChromeDriver is a class implementing the Interface WebDriver
public interface SearchContext{
}
public interface WebDriver extends SearchContext{
}
public class RemoteWebDriver implements WebDriver{
}
public class ChromeDriver extends RemoteWebDriver
{
}
WebDriver driver = new RemoteWebDriver();
WebDriver driver = new ChromeDriver();d