0% found this document useful (0 votes)
14 views2 pages

OOP Principles Explained

The document outlines the four main principles of Object-Oriented Programming (OOP): Encapsulation, Abstraction, Inheritance, and Polymorphism. Encapsulation combines attributes and methods into a single unit while providing data hiding; Abstraction hides unnecessary details, focusing on essential data; Inheritance allows a class to inherit properties from another, promoting code reusability; and Polymorphism enables objects to exhibit multiple behaviors based on context. Examples illustrate each principle, emphasizing their importance in programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

OOP Principles Explained

The document outlines the four main principles of Object-Oriented Programming (OOP): Encapsulation, Abstraction, Inheritance, and Polymorphism. Encapsulation combines attributes and methods into a single unit while providing data hiding; Abstraction hides unnecessary details, focusing on essential data; Inheritance allows a class to inherit properties from another, promoting code reusability; and Polymorphism enables objects to exhibit multiple behaviors based on context. Examples illustrate each principle, emphasizing their importance in programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OOPS Principles

1) Encapsulation
2) Abstraction
3) Inheritance
4) Polymorphism
Encapsulation
-> Encapsulation is used to combine attributes & methods as single entity / unit

-> Encapsulation provides data hiding

-> We can achieve encapsulation using Classes

class Demo {

//attributes

// methods

Abstraction
-> Abstraction means hiding un-necessary data and providing only required data
-> We can achieve Abstraction using interfaces & abstract classes

Ex : we will not bother about how laptop working internally

We will not bother about how car engine starting internally

Inheritance
-> Extending the properties from one class to another class is called as
Inheritance Ex: child will inherit the properties from parent
-> The main aim of inheritance is code re-usability
Note: In java, one child can't inherit properties from two parents at a time

Polymorphism
-> Exhibiting multiple behaviours based on situation is called as
Polymorphism Ex:-1 : in below scenario + symbol having 2 different
behaviours
10 + 20 ===> 30 (Here + is adding)
"hi" + "hello" ==> hihello (here + is concatinating)

Ex:-2:
When i come to class i will behave like a trainer

When i go to office i will behave like a employee

When i go to home i will behave like a family member

You might also like