Java Abstraction in addition to Encapsulation
Java Object Oriented Program
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
-------------------------------------------
iii) Abstraction
-------------------------------------------
> It is a Process of hiding implementation details in addition to showing exclusively functionality to the user
Two types of Methods
i) Concrete Methods (The Methods which are having body)
Syntax:
accessModifier retrunType / returnTypeNothing method Name() {
Statements
----------
-----------
-------------
}
ii) Abstract Methods (The Methods which are non having body)
Syntax:
accessModifier abstract returnType / returnTypeNothing MethodName();
> If nosotros know the method name, but don't know the method functionality in addition to therefore nosotros larn for Abstract Methods
> Java Class contains 100% concrete Methods.
> Abstract Class contains i or to a greater extent than abstract methods.
------------------------------------
Example:
Class1 (having 10 methods)
10 Methods are concrete Methods.
It is a Java Class
------------------------------
Class2 (having 10 methods)
5 Methods are concrete Methods in addition to five methods are abstract methods)
It is an Abstract Class
--------------------------------
Class3 (having 10 Methods)
All Methods are Abstract Methods
It is an Abstract Class
--------------------------------
Example for Abstract Class:
public abstract shape Bikes {
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 main(String[] args) {
//Bikes obj = novel Bikes();
}
}
--------------------------------
Note: We cannot practise Object/Instance inwards Abstract Class.
Note 2: In fellowship to utilisation Methods from Abstract Class in addition to therefore commencement nosotros postulate to implement abstract methods
in sub class.
Using methods from Abstract Class:
public shape HeroHonda extends Bikes{
public void engine() {
System.out.println("Bikes convey Engine");
}
public void wheels() {
System.out.println("Bikes convey Wheels");
}
public static void principal (String [] args){
HeroHonda abc = novel HeroHonda();
abc.seat();
abc.engine();
abc.wheels();
abc.handle();
}
}
-------------------------------------
Calling Methods inwards Abstract Class
public abstract shape Bikes {
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 main(String[] args) {
//Bikes obj = novel Bikes();
HeroHonda xyz = novel HeroHonda();
xyz.engine();
xyz.wheels();
}
}
------------------------------------------
How to inherit Abstract Class Methods?
By implementing abstract methods inwards Sub Class.
How to telephone hollo upward Methods inwards Abstract Class?
By creating the Object using Sub Class.
---------------------------------------------
Java Interfaces
> Interface is a Java type Definition block which is 100% abstract.
i) Class vs. Abstract Class
Java Classes convey 100% concrete Methods
Abstract Classes convey i or more/all abstract methods.
------------------------------------
ii) Class vs. Interface
Java Classes convey 100% concrete Methods
Java Interfaces convey 100% Abstract Methods
------------------------------------
iii) Abstract Class vs. Interface
Abstract Classes convey i or more/all abstract methods.
Java Interfaces convey 100% Abstract Methods
-----------------------------------------------
> All Interface Methods yesteryear default world in addition to abstract.
> static in addition to finally modifiers are non allowed for Interface methods
> In Interfaces Variables convey to initialize at the fourth dimension of proclamation only.
Ex:
int a;//Incorrect
a=100;
int b=200;//Correct
> In Interfaces Variables are world in addition to finally bydefault.
> Interfaces are going to last used using "implements" keyword.
-----------------------------------------------
Create Java Interface
Java Project
Java Package
Java Class / Java Interface
Example:
public interface Interface1 {
public void engine();
public void seat();
public void wheels();
public void handle();
}
Reuse Methods from Interface to Class
public shape ClassNew implements Interface1 {
public void engine() {
System.out.println("Bikes convey Engine");
}
public void seat() {
System.out.println("Bikes convey Seat");
}
public void wheels() {
System.out.println("Bikes convey Wheels");
}
public void handle() {
System.out.println("Bikes convey Handle");
}
public static void principal (String [] args){
ClassNew obj = novel ClassNew();
obj.seat();
obj.wheels();
obj.handle();
}
}
--------------------------------------------
Call methods inwards Interface
public interface Interface1 {
public void engine();
public void seat();
public void wheels();
public void handle();
public static void principal (String [] args){
ClassNew abc = novel ClassNew();
abc.handle();
abc.wheels();
}
}
-----------------------------------------------
Reuse Methods from a Class to but about other Class - using "extends" keyword
Reuse Methods from an Abstract Class to Class - using "extends" keyword
Reuse Methods from an Interface to Class - using "implements" keyword
---------------------------------------
Assignment
How to reuse Methods from an Interface to but about other Interface?
-------------------------------------------
iv) Encapsulation
It is a procedure of wrapping code in addition to information into a unmarried unit.
General Example:
Capsule (Mixer of several medicines)
Encapsulation is the technique making the fields inwards a shape someone in addition to providing access via world methods.
> It provides command over the data.
> By providing setter in addition to getter methods nosotros tin terminate brand a shape read exclusively or write only.
-------------------------------------
Example:
Class 1:
public shape Class1 {
private String advert = "Test Automation";
public String getName(){
return name;
}
public void setName(String newName){
name=newName;
}
public static void main(String[] args) {
Class1 obj = novel Class1();
obj.setName("Selenium alongside Java");
System.out.println(obj.getName());
}
}
----------------------------------
Class 2:
public shape Class2 extends Class1 {
public static void main(String[] args) {
Class2 obj2 = novel Class2();
//obj2.setName("Selenium alongside Java");
System.out.println(obj2.getName());
}
}
--------------------------------------
Java for Selenium the Conclusion
Java Environment Setup
Java Program Structure / Java Syntax
---------------------------------------
A) Java Fundamentals / Basics
1) Comments
2) Data Types
3) Modifiers
4) Variables
5) Operators
6) Flow Control
Conditional Statements
Loop Statements
8) String Handling
9) Arrays
10) IO Operations, in addition to File Handling
11) Methods
Built inwards Methods
User Defined Methods
13) Exception Handling
---------------------------------
B) Java OOPS
1) Inheritance
2) Polymorphism
3) Abstraction
4) Encapsulation
-------------------------------------------
Java Object Oriented Program
i) Inheritance
ii) Polymorphism
iii) Abstraction
iv) Encapsulation
-------------------------------------------
iii) Abstraction
-------------------------------------------
> It is a Process of hiding implementation details in addition to showing exclusively functionality to the user
Two types of Methods
i) Concrete Methods (The Methods which are having body)
Syntax:
accessModifier retrunType / returnTypeNothing method Name() {
Statements
----------
-----------
-------------
}
ii) Abstract Methods (The Methods which are non having body)
Syntax:
accessModifier abstract returnType / returnTypeNothing MethodName();
> If nosotros know the method name, but don't know the method functionality in addition to therefore nosotros larn for Abstract Methods
> Java Class contains 100% concrete Methods.
> Abstract Class contains i or to a greater extent than abstract methods.
------------------------------------
Example:
Class1 (having 10 methods)
10 Methods are concrete Methods.
It is a Java Class
------------------------------
Class2 (having 10 methods)
5 Methods are concrete Methods in addition to five methods are abstract methods)
It is an Abstract Class
--------------------------------
Class3 (having 10 Methods)
All Methods are Abstract Methods
It is an Abstract Class
--------------------------------
Example for Abstract Class:
public abstract shape Bikes {
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 main(String[] args) {
//Bikes obj = novel Bikes();
}
}
--------------------------------
Note: We cannot practise Object/Instance inwards Abstract Class.
Note 2: In fellowship to utilisation Methods from Abstract Class in addition to therefore commencement nosotros postulate to implement abstract methods
in sub class.
Using methods from Abstract Class:
public shape HeroHonda extends Bikes{
public void engine() {
System.out.println("Bikes convey Engine");
}
public void wheels() {
System.out.println("Bikes convey Wheels");
}
public static void principal (String [] args){
HeroHonda abc = novel HeroHonda();
abc.seat();
abc.engine();
abc.wheels();
abc.handle();
}
}
-------------------------------------
Calling Methods inwards Abstract Class
public abstract shape Bikes {
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 main(String[] args) {
//Bikes obj = novel Bikes();
HeroHonda xyz = novel HeroHonda();
xyz.engine();
xyz.wheels();
}
}
------------------------------------------
How to inherit Abstract Class Methods?
By implementing abstract methods inwards Sub Class.
How to telephone hollo upward Methods inwards Abstract Class?
By creating the Object using Sub Class.
---------------------------------------------
Java Interfaces
> Interface is a Java type Definition block which is 100% abstract.
i) Class vs. Abstract Class
Java Classes convey 100% concrete Methods
Abstract Classes convey i or more/all abstract methods.
------------------------------------
ii) Class vs. Interface
Java Classes convey 100% concrete Methods
Java Interfaces convey 100% Abstract Methods
------------------------------------
iii) Abstract Class vs. Interface
Abstract Classes convey i or more/all abstract methods.
Java Interfaces convey 100% Abstract Methods
-----------------------------------------------
> All Interface Methods yesteryear default world in addition to abstract.
> static in addition to finally modifiers are non allowed for Interface methods
> In Interfaces Variables convey to initialize at the fourth dimension of proclamation only.
Ex:
int a;//Incorrect
a=100;
int b=200;//Correct
> In Interfaces Variables are world in addition to finally bydefault.
> Interfaces are going to last used using "implements" keyword.
-----------------------------------------------
Create Java Interface
Java Project
Java Package
Java Class / Java Interface
Example:
public interface Interface1 {
public void engine();
public void seat();
public void wheels();
public void handle();
}
Reuse Methods from Interface to Class
public shape ClassNew implements Interface1 {
public void engine() {
System.out.println("Bikes convey Engine");
}
public void seat() {
System.out.println("Bikes convey Seat");
}
public void wheels() {
System.out.println("Bikes convey Wheels");
}
public void handle() {
System.out.println("Bikes convey Handle");
}
public static void principal (String [] args){
ClassNew obj = novel ClassNew();
obj.seat();
obj.wheels();
obj.handle();
}
}
--------------------------------------------
Call methods inwards Interface
public interface Interface1 {
public void engine();
public void seat();
public void wheels();
public void handle();
public static void principal (String [] args){
ClassNew abc = novel ClassNew();
abc.handle();
abc.wheels();
}
}
-----------------------------------------------
Reuse Methods from a Class to but about other Class - using "extends" keyword
Reuse Methods from an Abstract Class to Class - using "extends" keyword
Reuse Methods from an Interface to Class - using "implements" keyword
---------------------------------------
Assignment
How to reuse Methods from an Interface to but about other Interface?
-------------------------------------------
iv) Encapsulation
It is a procedure of wrapping code in addition to information into a unmarried unit.
General Example:
Capsule (Mixer of several medicines)
Encapsulation is the technique making the fields inwards a shape someone in addition to providing access via world methods.
> It provides command over the data.
> By providing setter in addition to getter methods nosotros tin terminate brand a shape read exclusively or write only.
-------------------------------------
Example:
Class 1:
public shape Class1 {
private String advert = "Test Automation";
public String getName(){
return name;
}
public void setName(String newName){
name=newName;
}
public static void main(String[] args) {
Class1 obj = novel Class1();
obj.setName("Selenium alongside Java");
System.out.println(obj.getName());
}
}
----------------------------------
Class 2:
public shape Class2 extends Class1 {
public static void main(String[] args) {
Class2 obj2 = novel Class2();
//obj2.setName("Selenium alongside Java");
System.out.println(obj2.getName());
}
}
--------------------------------------
Java for Selenium the Conclusion
Java Environment Setup
Java Program Structure / Java Syntax
---------------------------------------
A) Java Fundamentals / Basics
1) Comments
2) Data Types
3) Modifiers
4) Variables
5) Operators
6) Flow Control
Conditional Statements
Loop Statements
8) String Handling
9) Arrays
10) IO Operations, in addition to File Handling
11) Methods
Built inwards Methods
User Defined Methods
13) Exception Handling
---------------------------------
B) Java OOPS
1) Inheritance
2) Polymorphism
3) Abstraction
4) Encapsulation
-------------------------------------------