SlideShare uma empresa Scribd logo
1 de 10
Object Oriented Programing
By Noor wali Khan
UOCH
Class
• In an OOP model, some of the objects exhibit identical characteristics
(information structure and behavior)
• We say that they belongs to same class.
• In object-oriented programming, a class is a blueprint for
creating objects (a particular data structure), providing initial values
for state (member variables or attributes), and implementations of
behavior (member functions or methods).
• The class is a blueprint that defines a nature of a future object.
Class
• An instance is a specific object created from a particular class. Classes
are used to create and manage new objects and
support inheritance—a key ingredient in object-oriented
programming and a mechanism of reusing code.
• A class is a way of organizing information about a type of data
so a programmer can reuse elements when making multiple
instances of that data type—for example, if a programmer
wanted to make three instances of Car, maybe a BMW, a
Ferrari, and a Ford instance.
• The Car class would allow the programmer to store similar
information that is unique to each car (they are different
models, and maybe different colors, etc.) and associate the
appropriate information with each car.
Inheritance
• The capability of a class to derive properties and characteristics from
another class is called Inheritance.
• Inheritance is one of the most important feature of Object Oriented
Programming.
Sub Class:
• The class that inherits properties from another class is called Sub class or
Derived Class.
• Super Class:
• The class whose properties are inherited by sub class is called Base Class or
Super class
Why and when to use inheritance?
• Consider a group of vehicles. You need to create classes for Bus, Car
and Truck.
• The methods fuelAmount(), capacity(), applyBrakes() will be same for
all of the three classes.
• If we create these classes avoiding inheritance then we have to write
all of these functions in each of the three classes as shown in figure
(next slide)
Inheritance : Example
You can clearly see that above process results in duplication of same
code 3 times.
Inheritance
• This increases the chances of error and data
redundancy.
• To avoid this type of situation, inheritance is used.
• If we create a class Vehicle and write these three
functions in it and inherit the rest of the classes from
the vehicle class, then we can simply avoid the
duplication of data and increase re-usability.
Inheritance
• Look at the below diagram in which the three classes are inherited
from vehicle class:

Mais conteúdo relacionado

Mais procurados (11)

Constant a,variables and data types
Constant a,variables and data typesConstant a,variables and data types
Constant a,variables and data types
 
Programmatic Muddle Management
Programmatic Muddle ManagementProgrammatic Muddle Management
Programmatic Muddle Management
 
Ayush oops
Ayush oopsAyush oops
Ayush oops
 
Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)Class Members Access/Visibility Guide (Checklist)
Class Members Access/Visibility Guide (Checklist)
 
Introduction to Object Oriented Programming Class IX
Introduction to Object Oriented Programming Class IXIntroduction to Object Oriented Programming Class IX
Introduction to Object Oriented Programming Class IX
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
C plusplus
C plusplusC plusplus
C plusplus
 
Stack n heap
Stack n heapStack n heap
Stack n heap
 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1
 
Oopsinphp
OopsinphpOopsinphp
Oopsinphp
 
Day3
Day3Day3
Day3
 

Semelhante a OOP lecture 04

Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
Rakesh Madugula
 

Semelhante a OOP lecture 04 (20)

A350103
A350103A350103
A350103
 
object oriented programing lecture 1
object oriented programing lecture 1object oriented programing lecture 1
object oriented programing lecture 1
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Cble assignment powerpoint activity for moodle 1
Cble assignment powerpoint activity for moodle 1Cble assignment powerpoint activity for moodle 1
Cble assignment powerpoint activity for moodle 1
 
Introducing object oriented programming (oop)
Introducing object oriented programming (oop)Introducing object oriented programming (oop)
Introducing object oriented programming (oop)
 
OOM Unit I - III.pdf
OOM Unit I - III.pdfOOM Unit I - III.pdf
OOM Unit I - III.pdf
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
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
 
General oop concept
General oop conceptGeneral oop concept
General oop concept
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Oops
OopsOops
Oops
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Summer Training Project On C++
Summer Training Project On  C++Summer Training Project On  C++
Summer Training Project On C++
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Unit 3
Unit 3Unit 3
Unit 3
 
Programming paradigms
Programming paradigmsProgramming paradigms
Programming paradigms
 
OOP in C# Classes and Objects.
OOP in C# Classes and Objects.OOP in C# Classes and Objects.
OOP in C# Classes and Objects.
 

Mais de University of Chitral (15)

Compiler lecture 07
Compiler lecture 07Compiler lecture 07
Compiler lecture 07
 
Compiler lecture 06
Compiler lecture 06Compiler lecture 06
Compiler lecture 06
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Compiler lecture 05
Compiler lecture 05Compiler lecture 05
Compiler lecture 05
 
Oop lecture 06
Oop lecture 06Oop lecture 06
Oop lecture 06
 
Oop lecture 05
Oop lecture 05Oop lecture 05
Oop lecture 05
 
Compiler lecture 05
Compiler lecture 05Compiler lecture 05
Compiler lecture 05
 
Compiler lecture 04
Compiler lecture 04Compiler lecture 04
Compiler lecture 04
 
Compiler lecture 03
Compiler lecture 03Compiler lecture 03
Compiler lecture 03
 
Compiler lecture 01
Compiler lecture 01Compiler lecture 01
Compiler lecture 01
 
Compiler lecture 02
Compiler lecture 02Compiler lecture 02
Compiler lecture 02
 
O op lecture 04
O op lecture 04O op lecture 04
O op lecture 04
 
Oop lecture 03
Oop lecture 03Oop lecture 03
Oop lecture 03
 
Oop lecture 02
Oop lecture 02Oop lecture 02
Oop lecture 02
 
Oop lecture 01
Oop lecture 01Oop lecture 01
Oop lecture 01
 

Último

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
AnaAcapella
 
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
KarakKing
 

Último (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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Ữ Â...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
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
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
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
 
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...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

OOP lecture 04

  • 1. Object Oriented Programing By Noor wali Khan UOCH
  • 2. Class • In an OOP model, some of the objects exhibit identical characteristics (information structure and behavior) • We say that they belongs to same class. • In object-oriented programming, a class is a blueprint for creating objects (a particular data structure), providing initial values for state (member variables or attributes), and implementations of behavior (member functions or methods). • The class is a blueprint that defines a nature of a future object.
  • 3. Class • An instance is a specific object created from a particular class. Classes are used to create and manage new objects and support inheritance—a key ingredient in object-oriented programming and a mechanism of reusing code. • A class is a way of organizing information about a type of data so a programmer can reuse elements when making multiple instances of that data type—for example, if a programmer wanted to make three instances of Car, maybe a BMW, a Ferrari, and a Ford instance. • The Car class would allow the programmer to store similar information that is unique to each car (they are different models, and maybe different colors, etc.) and associate the appropriate information with each car.
  • 4.
  • 5.
  • 6. Inheritance • The capability of a class to derive properties and characteristics from another class is called Inheritance. • Inheritance is one of the most important feature of Object Oriented Programming. Sub Class: • The class that inherits properties from another class is called Sub class or Derived Class. • Super Class: • The class whose properties are inherited by sub class is called Base Class or Super class
  • 7. Why and when to use inheritance? • Consider a group of vehicles. You need to create classes for Bus, Car and Truck. • The methods fuelAmount(), capacity(), applyBrakes() will be same for all of the three classes. • If we create these classes avoiding inheritance then we have to write all of these functions in each of the three classes as shown in figure (next slide)
  • 8. Inheritance : Example You can clearly see that above process results in duplication of same code 3 times.
  • 9. Inheritance • This increases the chances of error and data redundancy. • To avoid this type of situation, inheritance is used. • If we create a class Vehicle and write these three functions in it and inherit the rest of the classes from the vehicle class, then we can simply avoid the duplication of data and increase re-usability.
  • 10. Inheritance • Look at the below diagram in which the three classes are inherited from vehicle class: