Object Oriented Programming_
Object Oriented Programming_
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
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
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;
}
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");
}
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:
For example
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.