SlideShare a Scribd company logo
1 of 30
OOP Concepts
Eng. Ahmed Farag
Object-oriented programming
• Object-oriented programming System(OOPs) is a programming
paradigm based on the concept of “objects” that contain data and
methods.
• The primary purpose of object-oriented programming is to increase
the flexibility and maintainability of programs.
• Object oriented programming brings together data and its
behavior(methods) in a single location(object) makes it easier to
understand how a program works.
What is an Object?
• Object: is a bundle of data and its behavior (often known as
methods).
• Objects have two characteristics: They have states and behaviors.
• Examples of states and behaviors
Example 1: Example 2:
Object: House Object: Car
State: Address, Color, Area State: Color, Brand, Weight, Model
Behavior: Open door, close door Behavior: Break, Accelerate, Slow Down,
Gear change.
What is an Object? Con…
class House {
String address;
String color;
double area;
void openDoor() {
//Write code here
}
void closeDoor() {
//Write code here
}
... ...
}
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Abstraction
• One of the most fundamental concept of OOPs is Abstraction.
• Abstraction is a process where you show only “relevant” data and
“hide” unnecessary details of an object from the user.
• For example:
• when you login to your Amazon account online, you enter your
user_id and password and press login, what happens when you
press login, how the input data sent to amazon server, how it gets
verified is all abstracted away from the you.
Abstraction Con…
• Another example of abstraction:
• A car in itself is a well-defined object, which is composed of several other
smaller objects like a gearing system, steering mechanism, engine, which are
again have their own subsystems. But for humans car is a one single object,
which can be managed by the help of its subsystems, even if their inner
details are unknown.
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Encapsulation
• Encapsulation simply means binding object state(fields) and
behavior(methods) together. If you are creating class, you are doing
encapsulation.
• Encapsulation is:
• Binding the data with the code that manipulates it.
• It keeps the data and the code safe from external interference
Encapsulation Con…
• The whole idea behind encapsulation is to hide the implementation
details from users. If a data member is private it means it can only be
accessed within the same class. No outside class can access private
data member (variable) of other class.
• However if we setup public getter and setter methods to update (for
example void setSSN(int ssn))and read (for example int getSSN()) the private
data fields then the outside class can access those private data fields
via public methods.
Encapsulation Con…
• This way data can only be accessed by public methods thus making
the private fields and their implementation hidden for outside
classes. That’s why encapsulation is known as data hiding.
Encapsulation Con…
• Example of Encapsulation in Java
• How to implement encapsulation in java:
1. Make the instance variables private so that they cannot be
accessed directly from outside the class. You can only set and
get values of these variables through the methods of the class.
2. Have getter and setter methods in the class to set and get the
values of the fields.
Encapsulation Con…
• A example of encapsulation is the class of java.util.Hashtable. User
only knows that he can store data in the form of key/value pair in a
Hashtable and that he can retrieve that data in the various ways. But
the actual implementation like, how and where this data is actually
stored, is hidden from the user. User can simply use Hashtable
wherever he wants to store Key/Value pairs without bothering about
its implementation.
Encapsulation Demo
• Demo using Java
Advantages of encapsulation
• It improves maintainability and flexibility.
• The fields can be made read-only.
• User would not be knowing what is going on behind the scene. They
would only be knowing that to update a field call set method and to
read a field call get method but what these set and get methods are
doing is purely hidden from them.
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Inheritance
• Inheritance is the mechanism by which an object acquires the
some/all properties of another object.
• The process by which one class acquires the properties(data
members) and functionalities(methods) of another class is called
inheritance.
Inheritance
• The aim of inheritance is to provide the reusability of code so that a
class has to write only the unique features and rest of the common
properties and functionalities can be extended from the another
class.
Inheritance
• Inheritance is a process of defining a new class based on an existing
class by extending its common data members and methods.
• Inheritance allows us to reuse of code, it improves reusability in your
java application.
• Note: The biggest advantage of Inheritance is that the code that is
already present in base class need not be rewritten in the child class.
Child and Base Class
• Child Class:
• The class that extends the features of another class is known as child class,
sub class or derived class.
• Parent Class:
• The class whose properties and functionalities are used(inherited) by
another class is known as parent class, super class or Base class.
• Note: The derived class inherits all the members and methods that
are declared as public or protected.
Inheritance Demo
• Demo using Java
Types of inheritance
• Single Inheritance: refers to a child and parent class relationship where a
class extends the another class.
• Multilevel inheritance: refers to a child and parent class relationship where
a class extends the child class. For example class C extends class B and class
B extends class A.
• Hierarchical inheritance: refers to a child and parent class relationship
where more than one classes extends the same class. For example, classes
B, C & D extends the same class A.
• Multiple Inheritance: refers to the concept of one class extending more
than one classes, which means a child class has two parent classes. For
example class C extends both classes A and B. Java doesn’t support
multiple inheritance
Constructors and Inheritance
• Constructor of sub class is invoked when we create the object of
subclass, it by default invokes the default constructor of super class.
Hence, in inheritance the objects are constructed top-down.
• The superclass constructor can be called explicitly using the super
keyword, but it should be first statement in a constructor.
• Example in java (Demo)
Object Oriented Programming features
Abstraction Encapsulation
Inheritance Polymorphism
Polymorphism
• Polymorphism is one of the OOPs feature that allows us to perform a
single action in different ways.
• Polymorphism is the capability of a method to do different things
based on the object that it is acting upon. In other words,
polymorphism allows you define one interface and have multiple
implementations.
Polymorphism
• In other words it means, one method with multiple implementation,
for a certain class of action. And which implementation to be used is
decided at runtime depending upon the situation (i.e., data type of
the object)
Static and Dynamic Polymorphism
• Polymorphism could be static and dynamic both.
• Method Overloading is static polymorphism while, Method
overriding is dynamic polymorphism.
Static Polymorphism
• Overloading in simple words means more than one method having
the same method name that behaves differently based on the
arguments passed while calling the method.
• This called static because, which method to be invoked is decided at
the time of compilation.(compile time)
Dynamic Polymorphism
• Overriding means a derived class is implementing a method of its
super class. The call to overridden method is resolved at runtime,
thus called runtime polymorphism
Polymorphism
• Demo

More Related Content

What's hot

the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented ProgrammingAida Ramlan II
 
Basic oop concepts - C++
Basic oop concepts - C++Basic oop concepts - C++
Basic oop concepts - C++Aleena Varghese
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented ConceptD Nayanathara
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)MD Sulaiman
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Object Vs Data Structure - Clean code chapter6
Object Vs Data Structure - Clean code chapter6Object Vs Data Structure - Clean code chapter6
Object Vs Data Structure - Clean code chapter6Maksud Chowdhury
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects yndaravind
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Vibhawa Nirmal
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4MOHIT TOMAR
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programmingSachin Sharma
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 

What's hot (20)

the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
Basic oop concepts - C++
Basic oop concepts - C++Basic oop concepts - C++
Basic oop concepts - C++
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Object Oriented Concept
Object Oriented ConceptObject Oriented Concept
Object Oriented Concept
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)Fundamentals of OOP (Object Oriented Programming)
Fundamentals of OOP (Object Oriented Programming)
 
Oop
OopOop
Oop
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Object Vs Data Structure - Clean code chapter6
Object Vs Data Structure - Clean code chapter6Object Vs Data Structure - Clean code chapter6
Object Vs Data Structure - Clean code chapter6
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners
 
Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4Oops concept in c++ unit 3 -topic 4
Oops concept in c++ unit 3 -topic 4
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
 
OOP Core Concept
OOP Core ConceptOOP Core Concept
OOP Core Concept
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 

Similar to Introduction to OOP concepts

Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentalsAnsgarMary
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsRaja Sekhar
 
Core java lessons
Core java lessonsCore java lessons
Core java lessonsvivek shah
 
Questpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPSQuestpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPSgdrealspace
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programmingAmar Jukuntla
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop pptdaxesh chauhan
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSkillwise Group
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionSamuelAnsong6
 

Similar to Introduction to OOP concepts (20)

Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Java OOP s concepts and buzzwords
Java OOP s concepts and buzzwordsJava OOP s concepts and buzzwords
Java OOP s concepts and buzzwords
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Principles of OOPs.pptx
Principles of OOPs.pptxPrinciples of OOPs.pptx
Principles of OOPs.pptx
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Questpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPSQuestpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPS
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
80410172053.pdf
80410172053.pdf80410172053.pdf
80410172053.pdf
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 

More from Ahmed Farag

Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part IAhmed Farag
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operatorsAhmed Farag
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingAhmed Farag
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBAhmed Farag
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Ahmed Farag
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++Ahmed Farag
 

More from Ahmed Farag (14)

Intro to php
Intro to phpIntro to php
Intro to php
 
MYSql manage db
MYSql manage dbMYSql manage db
MYSql manage db
 
Normalization
NormalizationNormalization
Normalization
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
Introduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDBIntroduction to NoSQL and MongoDB
Introduction to NoSQL and MongoDB
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
OOP C++
OOP C++OOP C++
OOP C++
 
Functions C++
Functions C++Functions C++
Functions C++
 
intro to pointer C++
intro to  pointer C++intro to  pointer C++
intro to pointer C++
 
Intro to C++
Intro to C++Intro to C++
Intro to C++
 

Recently uploaded

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 

Introduction to OOP concepts

  • 2. Object-oriented programming • Object-oriented programming System(OOPs) is a programming paradigm based on the concept of “objects” that contain data and methods. • The primary purpose of object-oriented programming is to increase the flexibility and maintainability of programs. • Object oriented programming brings together data and its behavior(methods) in a single location(object) makes it easier to understand how a program works.
  • 3. What is an Object? • Object: is a bundle of data and its behavior (often known as methods). • Objects have two characteristics: They have states and behaviors. • Examples of states and behaviors Example 1: Example 2: Object: House Object: Car State: Address, Color, Area State: Color, Brand, Weight, Model Behavior: Open door, close door Behavior: Break, Accelerate, Slow Down, Gear change.
  • 4. What is an Object? Con… class House { String address; String color; double area; void openDoor() { //Write code here } void closeDoor() { //Write code here } ... ... }
  • 5. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 6. Abstraction • One of the most fundamental concept of OOPs is Abstraction. • Abstraction is a process where you show only “relevant” data and “hide” unnecessary details of an object from the user. • For example: • when you login to your Amazon account online, you enter your user_id and password and press login, what happens when you press login, how the input data sent to amazon server, how it gets verified is all abstracted away from the you.
  • 7. Abstraction Con… • Another example of abstraction: • A car in itself is a well-defined object, which is composed of several other smaller objects like a gearing system, steering mechanism, engine, which are again have their own subsystems. But for humans car is a one single object, which can be managed by the help of its subsystems, even if their inner details are unknown.
  • 8. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 9. Encapsulation • Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are creating class, you are doing encapsulation. • Encapsulation is: • Binding the data with the code that manipulates it. • It keeps the data and the code safe from external interference
  • 10. Encapsulation Con… • The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. • However if we setup public getter and setter methods to update (for example void setSSN(int ssn))and read (for example int getSSN()) the private data fields then the outside class can access those private data fields via public methods.
  • 11. Encapsulation Con… • This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is known as data hiding.
  • 12. Encapsulation Con… • Example of Encapsulation in Java • How to implement encapsulation in java: 1. Make the instance variables private so that they cannot be accessed directly from outside the class. You can only set and get values of these variables through the methods of the class. 2. Have getter and setter methods in the class to set and get the values of the fields.
  • 13. Encapsulation Con… • A example of encapsulation is the class of java.util.Hashtable. User only knows that he can store data in the form of key/value pair in a Hashtable and that he can retrieve that data in the various ways. But the actual implementation like, how and where this data is actually stored, is hidden from the user. User can simply use Hashtable wherever he wants to store Key/Value pairs without bothering about its implementation.
  • 15. Advantages of encapsulation • It improves maintainability and flexibility. • The fields can be made read-only. • User would not be knowing what is going on behind the scene. They would only be knowing that to update a field call set method and to read a field call get method but what these set and get methods are doing is purely hidden from them.
  • 16. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 17. Inheritance • Inheritance is the mechanism by which an object acquires the some/all properties of another object. • The process by which one class acquires the properties(data members) and functionalities(methods) of another class is called inheritance.
  • 18. Inheritance • The aim of inheritance is to provide the reusability of code so that a class has to write only the unique features and rest of the common properties and functionalities can be extended from the another class.
  • 19. Inheritance • Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods. • Inheritance allows us to reuse of code, it improves reusability in your java application. • Note: The biggest advantage of Inheritance is that the code that is already present in base class need not be rewritten in the child class.
  • 20. Child and Base Class • Child Class: • The class that extends the features of another class is known as child class, sub class or derived class. • Parent Class: • The class whose properties and functionalities are used(inherited) by another class is known as parent class, super class or Base class. • Note: The derived class inherits all the members and methods that are declared as public or protected.
  • 22. Types of inheritance • Single Inheritance: refers to a child and parent class relationship where a class extends the another class. • Multilevel inheritance: refers to a child and parent class relationship where a class extends the child class. For example class C extends class B and class B extends class A. • Hierarchical inheritance: refers to a child and parent class relationship where more than one classes extends the same class. For example, classes B, C & D extends the same class A. • Multiple Inheritance: refers to the concept of one class extending more than one classes, which means a child class has two parent classes. For example class C extends both classes A and B. Java doesn’t support multiple inheritance
  • 23. Constructors and Inheritance • Constructor of sub class is invoked when we create the object of subclass, it by default invokes the default constructor of super class. Hence, in inheritance the objects are constructed top-down. • The superclass constructor can be called explicitly using the super keyword, but it should be first statement in a constructor. • Example in java (Demo)
  • 24. Object Oriented Programming features Abstraction Encapsulation Inheritance Polymorphism
  • 25. Polymorphism • Polymorphism is one of the OOPs feature that allows us to perform a single action in different ways. • Polymorphism is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations.
  • 26. Polymorphism • In other words it means, one method with multiple implementation, for a certain class of action. And which implementation to be used is decided at runtime depending upon the situation (i.e., data type of the object)
  • 27. Static and Dynamic Polymorphism • Polymorphism could be static and dynamic both. • Method Overloading is static polymorphism while, Method overriding is dynamic polymorphism.
  • 28. Static Polymorphism • Overloading in simple words means more than one method having the same method name that behaves differently based on the arguments passed while calling the method. • This called static because, which method to be invoked is decided at the time of compilation.(compile time)
  • 29. Dynamic Polymorphism • Overriding means a derived class is implementing a method of its super class. The call to overridden method is resolved at runtime, thus called runtime polymorphism

Editor's Notes

  1. It improves maintainability and flexibility and re-usability: for e.g. In the above code the implementation code of void setEmpName(String name) and String getEmpName() can be changed at any point of time. Since the implementation is purely hidden for outside classes they would still be accessing the private field empName using the same methods (setEmpName(String name) and getEmpName()). Hence the code can be maintained at any point of time without breaking the classes that uses the code. This improves the re-usability of the underlying class.