7) In Java you can define an interface or abstract class. When is it better to use an interface and when is it better to use an abstract class? code example
Example 1: interface vs abstract class java
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.
Abstract Class
1) Abstract class can contain abstract methods,
concrete methods or both
2) Except private we can have any access
specifier for methods in abstract class.
3) Except private variables can have any access
specifiers
4)We cannot achieve multiple inheritance using
abstract class.
Example 2: abstract classes and interfaces in java
abstract class have no implementation of methods functions inside it. the classes which extending abstract class have to implement it