1/* File name : MammalInt.java */
2public class MammalInt implements Animal {
3
4 public void eat() {
5 System.out.println("Mammal eats");
6 }
7
8 public void travel() {
9 System.out.println("Mammal travels");
10 }
11
12 public int noOfLegs() {
13 return 0;
14 }
15
16 public static void main(String args[]) {
17 MammalInt m = new MammalInt();
18 m.eat();
19 m.travel();
20 }
21}
1Interfaces specify what a class must do.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4We are using implements keyword for interface.
5
6Basic statement we all know in Selenium is
7WebDriver driver = new FirefoxDriver();
8WebDriver itself is an Interface.
9So we are initializing Firefox browser
10using Selenium WebDriver.
11It means we are creating a reference variable
12of the interface and creating an Object.
13So WebDriver is an Interface and
14FirefoxDriver is a class.
15
16
17
1public interface Exampleinterface {
2
3 public void menthod1();
4
5 public int method2();
6
7}
8
9class ExampleInterfaceImpl implements ExampleInterface {
10
11
12 public void method1()
13 {
14 //code here
15 }
16
17 public int method2()
18 {
19 //code here
20 }
21
22}
1Interfaces specify what a class must do.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4We are using implements keyword for interface.
5
6Basic statement we all know in Selenium is
7WebDriver driver = new FirefoxDriver();
8WebDriver itself is an Interface.
9So we are initializing Firefox browser
10using Selenium WebDriver.
11It means we are creating a reference variable
12of the interface and creating an Object.
13So WebDriver is an Interface and
14FirefoxDriver is a class.
15
1Interface blueprint of class.
2■ The main purpose of an interface is providing
3additional information and behaviors to any class that needs it
4■ The other way to achieve abstraction in java is via interface
5■ An interface is not a class, but acts similar,
6can be super type to a class
7■ To create an interface:the keyword interface is used instead of class
8■ Inheritance allows only one parent class,
9but it is possible to implement multiple interfaces to a class
10■ It’s possible to extend interfaces to other interfaces.
11■ there is only one access modifier allowed in interface ==> public
12*Interface can have: variable:(static & final by default),
13methods: (abstract methods, static methods, default method)
14*Interface cannot have: constructor, instance variable
15instance methods, blocks
16
17extends vs implements: both are used for inheriting
18extends: class extends class, interface extends interface
19(A class can inherit from one class only (extends)
20implements: class implements interface1, Interface2 …
21(A class can inherit multiple interfaces (implements)
22**RemoteWebDriver implements WebDriver,
23 / | \
24 chrome firefox opera
25 WebDriver driver = new ChromeDriver(); =>Interface
26TakeScreenShot,JavaScriptExecuter=>Interface
27List and Set also interface. You cannot create object in interface
1Interfaces specify what a class must do.
2It is the blueprint of the class.
3It is used to achieve total abstraction.
4We are using implements keyword for interface.
5
6Basic statement we all know in Selenium is
7WebDriver driver = new FirefoxDriver();
8WebDriver itself is an Interface.
9So we are initializing Firefox browser
10using Selenium WebDriver.
11It means we are creating a reference variable
12of the interface and creating an Object.
13So WebDriver is an Interface and
14FirefoxDriver is a class.
15List and Set also interface.
16You cannot create object in interface