Saturday, January 3, 2015

OOPS CONCEPTS FOR SELENIUM WEB DRIVER || SELENIUM WEB DRIVER INTERVIEW QUESTIONS


OOPS Concepts
Inheritance:We can extend the public objects from the parent class to a child class is nothing but Inheritance
Polymorphism: The ability to define more than one method with the same name is called Polymorphism. In java, there are two type of polymorphism: compile time polymorphism (overloading) and runtime polymorphism (overriding).
Overloading: It occurs when several methods have same names with different parameters
Public class A{
Public void add (int a, int b)
{
}
Public void add (String a, String b)
{
}
}
Overriding: It occurs when a child class method has the same name and the signature of the method is in parent class.
Public class B extends A{
Public void add (int a, int b, int c){


}
Encapsulation-Encapsulation is a process of binding (Hiding) the data that operates on a single class. This keeps the data safe from outside interface and misuse.
Ex:
public class Box
{
private int length;
private int width;
private int height;

public void setLength(int p)
{length = p;}

public void setWidth(int p)
{width = p;}

public void setHeight(int p)
{height = p;}

public int displayVolume()
{System.out.println(length*width*height)...
}

public static void main(String args [ ])
{
Box b1=new Box(3,4,5);
b1.displayvolume();
}
Abstraction-The process of abstraction is used to hide certain details of the object and only show the essential features of the object.
We can achieve abstraction with the help of access modifiers

Modifiers:
If you want to access a particular variable, method or class from anywhere, then make that variable accessible by using public modifier.

If you want to restrict a particular variable, method or class to be accessible outside the class, use private modifier.
Constructor:
A constructor is a special method that will be created with the class nameand it is called at the time of object creation (compile time). It can be used to initialize the default values at the time of object creation. It is not mandatoryfor the developer to write a constructor for the class
public class Constructor {
int x , y;
Constructor()
{
x = 15;
y = 20;
}
public void add(int a,int b)
{
x = a;
y = b;
int c=x+y;
System.out.println(c);
}
public void multiply()
{
System.out.println(x*y);
}
public static void main(String[] args) {
Constructor c=new Constructor();
c.add(5,3);
c.multiply();
}
}













No comments:

Post a Comment