SlideShare a Scribd company logo
1 of 26
Welcome To Our
Presentation
TOPIC:
Object Oriented Programming(OOP)
 Name: DM.Mehedi Hasan Abid
 Dept: CSE
Contents
• Introduction to Object Oriented Programming
• Encapsulation
• Association
• Inheritance
• Polymorphism
• Exception Handling
• Abstract Class and Interface.
• Advantage Object Oriented Programming
Introduction to Object Oriented
Programming
• An object is a unit of code that is responsible to accomplish a particular
task located inside code. In other way, we can tell that an object is a data
structure which solves a particular problem. To do its work, an object may
need some data and methods.
• From books we might have learned how to use classes (class library) or even learned how to write our own
classes and making object from them. But OOP is more than these. Designing beautiful classes, keep them
simple, make them for reusability and easy to change is the ultimate goal of OO code and design.
Object:
A thing that has identity, state, and behavior
• Identity: a distinguished instance of a class
• State: collection of values for its variables
• Behavior: capability to execute methods
* variables and methods are defined in a class.
Class:
In object-oriented programming, a class is an extensible program-code-template for creating objects,
providing initial values for state (member variables) and implementations of behavior (member functions or
methods).
Animal
Dog Cat Fish
• Encapsulation (Information Hiding):
• When creating new data types (classes) the details of the actual data and the way operations work is hidden
from the other programmers who will use those new data types
• Unnecessary implementation details should be hidden from the user
• In Java/C++, use classes and access modifiers (public, private, protected)
• Example: microwave, radio, iPad.
Example:
public class RunEncap{
public static void main(String args[]){
EncapTest encap = new EncapTest();
encap.setName(“MH Abid");
encap.setAge(22);
encap.setIdNum("151-51-226");
System.out.print("Name : " +
encap.getName() + " Age : " + encap.getAge());
}
}
OUTPUT:
Name : MH Abid Age : 22
Association:
• It represents a relationship between two or more objects where all objects have their own lifecycle
and there is no owner.
• Let’s take an example of relationship between Teacher and Student. Multiple students can associate
with a single teacher and a single student can associate with multiple teachers. Both object can be
created and deleted independently.
Here is an example of
“Association”
from our project.
In the picture we can see that in
the “Main”class we made an
object of “HomePage and
Sample”class.
• Inheritance
• In object-oriented programming, inheritance enables new objects to take on the properties of existing
objects. A class that is used as the basis for inheritance is called a superclass or base class. A class that
inherits from a superclass is called a subclass or derived class.
• Every Employee has a name, age, and birthday method as well as a salary and a pay
method.
class Person {
String name;
int age;
String id;
void birthday () {
}
}
class Employee extends Person {
double salary;
void pay () {
}
}
•Polymorphism:
“Poly”= Many, “Morphism”= forms
• Polymorphism = ability to take more than one form (objects have more than one type)
• A class can be used through its parent interface
• A child class may override some of the behaviors of the parent class.
Two types –
 Compile time polymorphism(Overloading).
 Run time polymorphism(Overriding).
• Compile time polymorphism:
• Compile time Polymorphism ( or Static polymorphism) Compile time polymorphism is nothing but the
method overloading in java.
• Run time polymorphism:
• The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a
child class object. Dynamic Binding/Runtime Polymorphism : Run time Polymorphism also known as
method overriding.
Exception Handling:
• An exception is a problem that arises during the execution of a program. A exception is a
response to an exceptional circumstance that arises while a program is running, such as an
attempt to divide by zero.
• Exceptions provide a way to transfer control from one part of a program to another.
exception handling keywords: try, catch, throw ,throws and finally.
class Exception
{
public static void main(String args[])
{
int a = 42 / 0;
}
}
• try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by
one or more catch blocks.
• catch: A program catches an exception with an exception handler at the place in a program where you want
to handle the problem. The catch keyword indicates the catching of an exception.
• throw: throw keyword is used to throw an exception explicitly. Only object of Throwable class or its sub
classes can be thrown. Program execution stops on encountering throw statement.
Throws:
Any method capable of causing
exceptions must list all the exceptions
possible during its execution, so that
anyone calling that method gets a prior
knowledge about which exceptions to
handle. A method can do so by using
the throws keyword.
Finally:
A finally keyword is used to create a
block of code that follows a try
block. A finally block of code
always executes whether or not
exception has occurred.
• Abstract Class :
• Classes which contain one or more abstract methods or abstract properties, such methods or properties do
not provide implementation.
• Syntax :
• abstract class class name { }
• Abstract method:
• Method that are declared without any body within an abstract class is known as abstract method. The
method body will be defined by its subclass. Abstract method can never be final and static. Any class that
extends an abstract class must implement all the abstract methods declared by the super class.
• Syntax :
• Abstract return_typefunction_name ();
Output will be Ferrari moves
firster than all cars
• Interface:
• An interface is a description of the actions that an object can do. For example when you flip a light switch,
the light goes on, you don't care how, just that it does. In Object Oriented Programming, an Interface is a
description of all functions that an object must have in order to be an "X“.
• Syntax:
• interface interface name { }
Interface
Implementation
This is how a class implements an
interface. It has to provide the body
of all the methods that are declared
in interface.
Note: class implements interface but
an interface extends another
interface.
Difference between abstract class and Interface
Advantages of OOP
• • Simplicity: software objects model real world objects, so the complexity is reduced
and the program structure is very clear;
• • Modularity: each object forms a separate entity whose internal workings are
decoupled from other parts of the system;
• • Extensibility: adding new features or responding to changing operating
environments can be solved by
• • Maintainability: objects can be maintained separately, making locating and fixing
problems easier;
• •Re-usability: objects can be reused in different programs
THANK YOU

More Related Content

What's hot

Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Michelle Anne Meralpis
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentalsjavaease
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languagesppd1961
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionPritom Chaki
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSkillwise Group
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming conceptsrahuld115
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaGlenn Guden
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Sakthi Durai
 

What's hot (20)

Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Oops in java
Oops in javaOops in java
Oops in java
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentals
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Oop
OopOop
Oop
 
SKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPTSKILLWISE - OOPS CONCEPT
SKILLWISE - OOPS CONCEPT
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1 Java Programming Paradigms Chapter 1
Java Programming Paradigms Chapter 1
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 

Similar to Object oriented programming

Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4thConnex
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csjaved75
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptBill Buchan
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionSamuelAnsong6
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1Geophery sanga
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++KAUSHAL KUMAR JHA
 
12_oop templa.pptx
12_oop templa.pptx12_oop templa.pptx
12_oop templa.pptxRokaKaram
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxethiouniverse
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascriptUsman Mehmood
 

Similar to Object oriented programming (20)

Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Presentation 4th
Presentation 4thPresentation 4th
Presentation 4th
 
UNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year csUNIT-IV WT web technology for 1st year cs
UNIT-IV WT web technology for 1st year cs
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
oop.pptx
oop.pptxoop.pptx
oop.pptx
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
12_oop templa.pptx
12_oop templa.pptx12_oop templa.pptx
12_oop templa.pptx
 
Oopsinphp
OopsinphpOopsinphp
Oopsinphp
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Object Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptxObject Oriented Programming Tutorial.pptx
Object Oriented Programming Tutorial.pptx
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 

Recently uploaded

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Object oriented programming

  • 3.  Name: DM.Mehedi Hasan Abid  Dept: CSE
  • 4. Contents • Introduction to Object Oriented Programming • Encapsulation • Association • Inheritance • Polymorphism • Exception Handling • Abstract Class and Interface. • Advantage Object Oriented Programming
  • 5. Introduction to Object Oriented Programming • An object is a unit of code that is responsible to accomplish a particular task located inside code. In other way, we can tell that an object is a data structure which solves a particular problem. To do its work, an object may need some data and methods. • From books we might have learned how to use classes (class library) or even learned how to write our own classes and making object from them. But OOP is more than these. Designing beautiful classes, keep them simple, make them for reusability and easy to change is the ultimate goal of OO code and design.
  • 6. Object: A thing that has identity, state, and behavior • Identity: a distinguished instance of a class • State: collection of values for its variables • Behavior: capability to execute methods * variables and methods are defined in a class. Class: In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). Animal Dog Cat Fish
  • 7. • Encapsulation (Information Hiding): • When creating new data types (classes) the details of the actual data and the way operations work is hidden from the other programmers who will use those new data types • Unnecessary implementation details should be hidden from the user • In Java/C++, use classes and access modifiers (public, private, protected) • Example: microwave, radio, iPad.
  • 8. Example: public class RunEncap{ public static void main(String args[]){ EncapTest encap = new EncapTest(); encap.setName(“MH Abid"); encap.setAge(22); encap.setIdNum("151-51-226"); System.out.print("Name : " + encap.getName() + " Age : " + encap.getAge()); } } OUTPUT: Name : MH Abid Age : 22
  • 9. Association: • It represents a relationship between two or more objects where all objects have their own lifecycle and there is no owner. • Let’s take an example of relationship between Teacher and Student. Multiple students can associate with a single teacher and a single student can associate with multiple teachers. Both object can be created and deleted independently.
  • 10. Here is an example of “Association” from our project. In the picture we can see that in the “Main”class we made an object of “HomePage and Sample”class.
  • 11. • Inheritance • In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a superclass or base class. A class that inherits from a superclass is called a subclass or derived class.
  • 12. • Every Employee has a name, age, and birthday method as well as a salary and a pay method. class Person { String name; int age; String id; void birthday () { } } class Employee extends Person { double salary; void pay () { } }
  • 13. •Polymorphism: “Poly”= Many, “Morphism”= forms • Polymorphism = ability to take more than one form (objects have more than one type) • A class can be used through its parent interface • A child class may override some of the behaviors of the parent class. Two types –  Compile time polymorphism(Overloading).  Run time polymorphism(Overriding).
  • 14. • Compile time polymorphism: • Compile time Polymorphism ( or Static polymorphism) Compile time polymorphism is nothing but the method overloading in java.
  • 15. • Run time polymorphism: • The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Dynamic Binding/Runtime Polymorphism : Run time Polymorphism also known as method overriding.
  • 16. Exception Handling: • An exception is a problem that arises during the execution of a program. A exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. • Exceptions provide a way to transfer control from one part of a program to another. exception handling keywords: try, catch, throw ,throws and finally. class Exception { public static void main(String args[]) { int a = 42 / 0; } }
  • 17. • try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. • catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception. • throw: throw keyword is used to throw an exception explicitly. Only object of Throwable class or its sub classes can be thrown. Program execution stops on encountering throw statement.
  • 18. Throws: Any method capable of causing exceptions must list all the exceptions possible during its execution, so that anyone calling that method gets a prior knowledge about which exceptions to handle. A method can do so by using the throws keyword.
  • 19. Finally: A finally keyword is used to create a block of code that follows a try block. A finally block of code always executes whether or not exception has occurred.
  • 20. • Abstract Class : • Classes which contain one or more abstract methods or abstract properties, such methods or properties do not provide implementation. • Syntax : • abstract class class name { } • Abstract method: • Method that are declared without any body within an abstract class is known as abstract method. The method body will be defined by its subclass. Abstract method can never be final and static. Any class that extends an abstract class must implement all the abstract methods declared by the super class. • Syntax : • Abstract return_typefunction_name ();
  • 21. Output will be Ferrari moves firster than all cars
  • 22. • Interface: • An interface is a description of the actions that an object can do. For example when you flip a light switch, the light goes on, you don't care how, just that it does. In Object Oriented Programming, an Interface is a description of all functions that an object must have in order to be an "X“. • Syntax: • interface interface name { }
  • 23. Interface Implementation This is how a class implements an interface. It has to provide the body of all the methods that are declared in interface. Note: class implements interface but an interface extends another interface.
  • 24. Difference between abstract class and Interface
  • 25. Advantages of OOP • • Simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear; • • Modularity: each object forms a separate entity whose internal workings are decoupled from other parts of the system; • • Extensibility: adding new features or responding to changing operating environments can be solved by • • Maintainability: objects can be maintained separately, making locating and fixing problems easier; • •Re-usability: objects can be reused in different programs