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

Pillars of OOPs

Object-Oriented Programming (OOP) is a programming paradigm that emphasizes code reusability and maintainability through concepts such as classes, objects, inheritance, abstraction, encapsulation, and polymorphism. These concepts can be applied across various programming languages like Python, Java, and C++. The document provides examples and explanations for each core concept, illustrating their practical applications in programming.

Uploaded by

Kartik Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Pillars of OOPs

Object-Oriented Programming (OOP) is a programming paradigm that emphasizes code reusability and maintainability through concepts such as classes, objects, inheritance, abstraction, encapsulation, and polymorphism. These concepts can be applied across various programming languages like Python, Java, and C++. The document provides examples and explanations for each core concept, illustrating their practical applications in programming.

Uploaded by

Kartik Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Object Oriented

Programming
in 60 sec
WhatisOOP

OOP is an mostly used programming paradigm


which provides code reusability and flexibility to
write easily maintainable and scalable code while
developing application

Core concepts in OOP

l. Class
2. Object
3. Inheritance
4. Abstraction
5. Encapsulation
6. Polymorphism

well these are not specific to an particular


programming language can be used in all
programming languages that supports OOPS
concepts like python, java, cpp and more.

cl(; rn () f'l tCC1 l'O 1~r1


...___J
C' I swipe ➔
1. Class and Object

A class is blueprint of an object which includes set


of properties and Object is an instance of a class
which can created by from class.

Example: Consider a candle mould which is a


blueprint of candle as a class which can create
many candles and those candles are objects.

class CandleMould { // class


void makeCandle (int n) {
System.out. println {"Making candle" + " " + n);

public class Main {


public static void main {String[] args) {
CandleMould mould_l = new CandleMould{); // object 1 of class CandleMould
CandleMould mould_2 = new CandleMould{); // object 2 of class CandleMould
mould_l . makeCandle ( l );
mould_2. makeCandle {2);

demonprogrammer swipe ➔
2. Inheritance
Inheriting or acquiring properties from the parent
class by a child class is know as Inheritance
• There are mainly 5 types:
1. Single Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
Example: As child of your father you have authority
to get the share in property or assets of your family,
that mean a child class can access the methods
and properties of parent class.
class Parent {
String familyName = "xyz" ;
int wealth= 200000 ;

}
public class Main {
public static void main {String[] args) {
Child obj= new Child{);
String familyName = obj.familyName;
int wealth= obj.wealth;
System.out. println (familyName+ " " + wealth);

swipe ➔
demonprogrammer
3. Abstraction
Hiding the complex implementations and showing
only the functionality to user is know as Abstraction

Example: Consider about TV remote we don't know


how its built and how complex it is in
implementation but it is easy and simple to use by
the user by hiding the implementation.

// abstraction of buttons
abstract class TVRemote{
abstract void turnOnTV ();
abstract void turnOffTv ();
}
//implementation
class Buttons extends TVRemote {
void turnOnTV () {
System.out. println ( "Turning on TV" );

}
public class Main {
public static void main (String[] args) {
Buttons remote= new Buttons();
remote. turnOnTV ();
remote. turnOffTv ();

swipe ➔
demonprogrammer
4. Encapsulation
Group the data and methods in a particular class
and not allowing other classes to access the data
directly but only possible by methods of the class.
we have to define setter and getter to methods to
initialize data and to get the data.

Example: whenever we are on conversation we


don't directly speak about our details unless the
opposite person asks about specific data like our
name,age and etc ..

class Person {

private String name; // data-> name

public void setName (String myName){ // method to initialize or to change the value
name= myName;

public String getName (){ // method to get the name


return name;

class Main {
public static void main (String[J args) {
Person obj= new Person();
obj. setName ( "John Wick" ); // setting the value by methods of person class
String name= obj. getName (); //getting th value of person name
System.out. println ( "My name is "+name);

swipe ➔
demonprogrammer
5. Polymorphism
Poly means many and Morph means shape, having
ability to change the execution of the programme
according the different functionalities is know
as Polymorphism
• There are mainly two types
1. Compile time polymorphism - the state of
execution will be declared at complie time which
is static in nature
• a. Method overloading - can be defined as
methods with same name but different
parameters

class Calculator {
int add (int a, int b){ // method with two parameters but same name
return a+b;

int add (int a, int b, int c){ //method with three parameters but same name
return a+b+c;

public class Main {


public static void main (String[] args) {
Calculator object = new Calculator();
System . out. println (object. add ( l , 2));
System . out. println (object. add ( 3, 6, 7 ));

swipe ➔
demonprogrammer
b. Operator Overloading - java doesn't supprots
operator overloading
2. Runtime polymorphism - the execution state of
programme will be declared at runtime which is
dynamic in nature
a. Method Overriding - Overriding the execution of a
method by another method having same name
and same parameters but belongs to different
class is known as method overriding.

II method overriding
class calculator {
int add (int a, int b){
return a+b;

}
class AdvanceCalculator extends calculator {
int add (int a, int b) {
return a+b+10;

}
public class Main {
public static void main (String[] args) {
AdvanceCalculator obj= new AdvanceCalculator();
int result= obj. add ( l , 4 );
System.out. println (result);

demonprogrammer

You might also like