Java Abstraction together with Encapsulation

Java Abstraction as well as Encapsulation
 

Java Object Oriented Programming

i) Inheritance

ii) Polymorphism
----------------
iii) Abstraction

iv) Encapsulation
--------------------------------------
Abstraction

> It is a procedure of hiding implementation details as well as showing entirely functionality to the user.

Two types of Methods inwards Java

1) Concrete Methods (The methods which are having body)

Example:

public void add(){
Statements
---------
--------
-----------
}

2) Abstract Methods (The methods which are non having body)

Ex:

public void add();

--------------------------------------
> If nosotros know the method name, but don't know the method functionality, as well as hence nosotros become for Abstract methods.

> Java Class contains 100% concrete methods.

> Abstract shape contains ane or to a greater extent than abstract methods.
--------------------------------------

Example:

Class 1 (having 10 methods)

10 methods are concrete methods

It is a Java Class

Class two (having 10 methods)

(5 concrete methods as well as v abstract methods)

Abstract class

Class iii (having 10 methods)

(All 10 methods are abstract methods)

Abstract class
----------------------------
Example:

Abstract Class

public abstract shape Bike {

public void handle(){
System.out.println("Bikes convey Handle");
}

public void seat(){
System.out.println("Bikes convey Seats");
}

public abstract void engine();

public abstract void wheels();

public static void master copy (String [] args){
HeroHonda obj = novel HeroHonda();
obj.engine();
obj.wheels();
}
}
----------------------------------
Sub Class

public shape HeroHonda extends Bike{
@Override
public void engine() {
System.out.println("Bikes convey Engine");
}

@Override
public void wheels() {
System.out.println("Bikes convey Wheels");
}

public static void master copy (String [] args){
//Create Object
HeroHonda objHH = novel HeroHonda();   
objHH.engine();
objHH.seat();
objHH.wheels();
objHH.handle();
}
}
--------------------------
Interfaces

Selenium IDE has User Interface (Integrated Development Environment)

Selenium WebDriver is a Programming Interface.
---------------------------
UFT/QTP has both IDE also every bit Programming Interface.
------------------------------
Java Interfaces

> Interface is a Java type Definition block which is 100% abstract

> All the Interface methods past times default world as well as abstract.

> static as well as in conclusion modifiers are non allowed for interface methods.

> In Interfaces variables convey to initialize at the fourth dimension of declaration.

int a;//Incorrect

int a =10; //Correct

> In Interfaces variables are public, static, as well as in conclusion past times default.

> Interface is going to hold upwards used using "implements" keyword.
---------------------------------------------------
Example for Java Interface:

1) Create an Interface

public interface Interface1 {
public void engine();
public void wheels();
public void seat();
public void handle();

public static void master copy (String [] args){
ClassNew objx = novel ClassNew();   
objx.engine();
objx.wheels();
}
}

2) Reuse Methods from Interface to Class

public shape ClassNew implements Interface1{

   
public void engine() {
System.out.println("Bikes convey Engine");
}
   
public void wheels() {
System.out.println("Bikes convey Wheels");
}

   
public void seat() {
System.out.println("Bikes convey Seats");
}

public void handle() {
System.out.println("Bikes convey Handle");
}

public static void master copy (String [] args){
ClassNew obj = novel ClassNew();
obj.seat();
obj.wheels();
obj.engine();
obj.handle();
}
}
---------------------------------------------
Note:

From Class (Concrete shape or Abstract Class) to Class nosotros usage "extends" keyword

From Interface to Class nosotros usage "implements" keyword
-----------------------------------
Encapsulation:

It is a procedure of wrapping code as well as information into a unmarried unit.

Encapsulation is the technique making the fields inwards a shape soul as well as providing access via world methods.

> It provides command over the data.

> By providing setter as well as getter methods nosotros tin brand a shape read entirely or write only.

Example:
Class1:

public shape Class1 {
private String advert = "Test Automation";

public String getName(){
return name;
}
public void setName(String newName){
name=newName;   
}

public static void master copy (String [] args){
Class1 obj = novel Class1();
System.out.println(obj.getName());
}
}
--------------------------------
Class2:
public shape Class2 extends Class1 {

public static void main(String[] args) {
Class2 obj2 = novel Class2();
obj2.setName("Selenium");
System.out.println(obj2.getName());
}
}
--------------------------------------
Java for Selenium

Java Environment setup
Java Program Structure
A) Java Fundamentals
    1) Comments inwards Java
    2) Data Types
    3) Modifiers
    4) Variables
    5) Operators
    6) Flow Control
        Conditional Statements
        Loop Statements
    8) Arrays
    9) String Handling inwards Java
    10) I/O operations as well as File handling
    11) Java Methods
        Built inwards methods
        User defined methods
    13) Exception handling
-------------------------------
B) Java OOPS

    1) Inheritance
    2) Polymorphism
    3) Abstraction
    4) Encapsulation
----------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post