Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Object Oriented Programming_

Uploaded by

Imam Masum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Object Oriented Programming_

Uploaded by

Imam Masum
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

THE FOUR PILLARS OF OBJECT

ORIENTED PROGRAMMING(00P)

These principles are called the four pillars of object-oriented programming (OOP). These
four pillars are Inheritance, Polymorphism, Encapsulation and Abstraction.

Inheritance 01
Polymorphism 02
Abstraction
03
Encapsulation 04
Inheritance
In Java, it is possible to inherit attributes and methods from one class to another. We group the
"inheritance concept" into two categories:
subclass (child) - the class that inherits from another class
superclass (parent) - the class being inherited from

For example

superclass (parent)
String brand;
String processor;
int memory;
Computer double price;

Subclass Subclass

Desktop extends Computer laptop extends Computer

brand( Dell ); brand( HP );


processor( Intel Core i7 ); processor( Intel Core i5 );
memory(16GB); memory(32GB);
price(90,0000); price(70,0000);

In this instance:

The basic class of computer has brand, processor, memory, price, and ways to mimic starting up
and show general information.

There are two child classes—desktop and laptop—and parent class is Computer at first. The brand
processor ,memory, price is declared in the Pran class. Computer is the name of the first parent
plastic that is opened. The two classes I have will automatically contain all of the variables that I
eliminated. Price, brand, CPU, and RAM may all be customized to our preferences.
Polymorphism

Polymorphism is "Many forms" is what polymorphism refers to, and it happens when there are
several classes that are connected to one another through inheritance.

Polymorphism

Overloading Compile-time behavior

Overriding Runtime behavior

Overloading

Overloading: Overloading occurs when multiple methods in the same class have the same name
but different parameter lists. It allows methods to have different behaviors based on the
arguments passed to them. Overloading is resolved at compile time and is also known as
compile-time polymorphism or static polymorphism.

For example

class Calculator {
public int add(int a, int b){
return a + b;
}

public int add(int a, int b, int c){


return a + b+c;
}
public int add(int a, int b,int c, int d){
return a + b+c+d;
}
}
Overriding

Overriding: Overriding occurs when a subclass provides a specific implementation for a method
that is already defined in its superclass. The method in the subclass must have the same name,
return type, and parameter list as the method in the superclass. Overriding allows a subclass to
provide its specific implementation of a method, which is invoked at runtime based on the actual
object type. Overriding is resolved at runtime and is also known as runtime polymorphism or
dynamic polymorphism.

For example

superclass (parent)
class InputDevice {
public void type() {
System.out.println("Typing on an input device");
}

class Keyboard extends InputDevice {


@Override
public void type() {
System.out.println("Typing on a keyboard");
}
}

class Mouse extends InputDevice {


@Override
public void type() {
System.out.println("Typing on a Mouse");
}
}

Abstraction

Abstraction is a process of hiding the implementation details and showing only functionality to
the user.

For example
Television remote control
In this example:

The television remote control serves as an abstraction, providing a simplified interface for
interacting with the television.
Users interact with the remote control by pressing buttons, which abstract away the detailed
operations required to perform various actions on the TV.
Users don't need to understand the inner workings of the television to use the remote control
effectively. They can simply press the appropriate buttons to achieve their desired outcomes,
such as changing channels or adjusting the volume.

Encapsulation

The meaning of Encapsulation, is to make sure that "sensitive" data is hidden from users. To achieve
this, you must:

declare class variables/attributes as private


provide public get and set methods to access and update the value of a private variable

For example

Bank's ATM (Automated Teller Machine)

User Interface Encapsulation();


Transaction Processing Encapsulation();
Database Access Encapsulation();
Security Encapsulation();

In summary, encapsulation in an ATM system ensures that various components and functionalities
are encapsulated within well-defined modules, promoting modularity, security, and maintainability.
By abstracting away complexity and exposing controlled interfaces, encapsulation enhances the
reliability, security, and usability of ATM systems, enabling customers to conduct banking
transactions efficiently and securely.

You might also like