Java OOPS: OOPS in Selenium

OOPS in Selenium


Object means a real-world entity such as a pen, chair, table, etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects.


It simplifies software development and maintenance by providing some concepts:

    1. Object
    2. Class
    3. Inheritance
    4. Polymorphism 
    5. Abstraction
    6. Encapsulation



  Classes in Java            


A class is a user-defined blueprint or prototype from which objects are created. It represents the set of variables and methods that are common to all objects of one type.

Modifiers : A class can be public or has default access

Class name : The name should begin with alphabets, and most of the time, we follow the CamelCase convention; the first letter of all the words is in the Upper case.

Superclass : Like everyone in the real world, even Java classes can have parents, these parents are called as Superclass. Any given Class can have only one class as Parent. ( Don't ask whether it is the mother or father)

Interfaces : Interfaces are empty containers that set the rules for other interfaces and classes.

Body A class body is contained within curly braces { }, the class can contain methods, variable, inner classes, constructors, static blocks, default blocks

Object : As everyone says, it is like a real object in our world, But Objects are nothing but the container of the non-static elements in the class, Objects will have value, address 


Object Creation

We can create an object for any class in Java; to create, we will use the most preferred way. i.e., with a new keyword.

Type variable = new constructor();
A objA = new A();


"Type" is nothing but the type of the object.
"variable" is nothing but any name for the object
"new" is the keyword to reserve the memory space on the stack


"Constructor" is the one who will load all the non-static elements in the class into space that reserved by the new keyword; the Constructor name is the same as the Class name.

We can access all non-static members of the class via object reference with the dot operator.

public class A {
	public void test() {
		System.out.println("test method");
	}
	public static void main(String[] args) {
		A objA = new A();
		objA.test();
	}
}

Comments

Popular posts from this blog

Java OOPS:OOPS Concepts Overview

Java OOPS:Constructors in Java – A complete study!!