the inheritance code example

Example 1: inheritance

it is used to define relationship between two class, 
which a child class occurs all the properties and behaviours of a parent class. 
Provides code reusability.
Ex: in my framework I have a TestBase class which I store 
all my reusable code and methods. My test execution classes and 
elements classes will extend the TestBase in order to reuse the code.

Example 2: Inheritance

Builds relations between classes, main purpose: 
create a TEST BASE CLAS and use it in other classes.
Inheritance allows a class to inherit properties 
(objects, variables, methods) from another source (class or interface). 
Allows code reusability and easy to maintain.
SUPER CLASS (also known as parent or base class): 
is the class where the fields are being inherited from. 
SUB CLASS (also known as the child or derived class): 
is the class inheriting the properties
INHERITANCE EXAMPLE
In my framework I have a TestBase class where I store 
all my reusable code and methods. My test execution classes, 
and elements classes will extend the TestBase in order to reuse the code. 
My framework follow POM and some pages have similar actions, 
so I can easily use those similar actions and fields 
by inheriting them from the ready classes.
Example: Base Page Class and Test Base Class. 
These 2 class are being inherited from so many different classes. 
For Example; In Pages Package, Base Page Class is being extended 
by all the class by Base Package. So that Constructor 
can be automatically be called in the sub classes. 
That way you will be able to locate the elements 
by using same driver. Test Base Class can also be inheritance. 
One driver, TestNG framework one before method to 
setup browser and reuse it every single test class it. 
By inheriting them to other test class. These 2 class are 
abstract class and meant to be inherited to other classes. 
We are not creating any object in these 2 class. 
These class is super class. Comes from Selenium library WebDriver, 
takes Screenshots, javascriptexecuter these are interface. 
List and Set also interface. You cannot create object in interface. 
They are only being reference. These are also example for abstraction.

Tags:

Java Example