Selenium WebDriver -Object
- Object is an Instance of class. In other words we can say object is bundle of related methods and variables.
- An entity that has state and behaviour is known as an object e.g. chair, bike, marker, pen, table, car etc.
- Every object has Its own states and behavior. Objects are generally used with constructors In java. Understanding of object is very Important for Selenium WebDriver learner.
How to create object?
You can create object of class vehicle
using new keyword as bellow.
public class vehicle {
public static void main(String[] args)
{
//Created object for vehicle class
using new keyword.
//bicycle is the reference variable of
this object.
vehicle bicycle = new vehicle("Black");
}
//Constructor with color parameter
passed. It will retrieve value from object vehicle.
public vehicle(String color){
//Retrieved value will be printed.
System.out.println("Color Of
vehicle is "+color);
}
}
Console Output will looks like bellow
when you will run above example.
Color Of vehicle is Black
In above example, Used one constructor
to pass the value of object. We will look about constructor In my
upcoming post. Please remember here one thing - bicycle is not an
object. It is reference variable of object vehicle. Based on this
example, Now we can say that object has three parts as bellow.
Declaration : Variable declaration for
object. In this example, bicycle is the reference variable for
object.
Instantiation : Object creation using
new keyword is called as Instantiation.
Initialization : Call to a constructor
is known as object initialization.
No comments:
Post a Comment