SlideShare a Scribd company logo
Classes (and Objects)
CLASSES AND OBJECTS MADE FROM THEM
INHERITANCE, INTERFACES
1
Primitive Types
2
Non-primitive types
Arrays – a named structure of primitive/non-primitive indexed by an integer value
Strings – a collection of characters
User defined Structure and Classes
3
User defined structures (C language)
struct person
{
char firstName[20];
char lastName[20];
int dob_year;
}
struct baseballPlayer
{
struct person info;
char team[20];
float battingAverage;
}
Here a person is a classification
of how to capture data about a
person.
A baseballPlayer is a
classification is a special type of
person.
Should the programming language define a Baseball Player for all users
(application developers) to have to use or should the language allow
the user to define a Baseball Player however they want.
4
Creating and Initializing an instance of a
structure (classification), and print
struct person p1 = {
“Joe”,
”Smith”,
1990
};
struct baseballPlayer bbp1 = {
{“Joe”,”Dimaggio”,1914 }
“Yankees”,
0.325
};
printf("Name: %sn", bbp1.info.firstName);
printf("Name: %sn", p1.firstName);
5
Modifying structure data
What if the DOB_year was set to 3030?
What if the baseball player’s team was set to “Rams”?
What if the baseball player’s batting average was set to -0.325? or 11.234 or “Jello”.
What if the person’s last name is “” ( ie Blank)
What if a program over-wrote an array and destroyed data in a structure?
Solution: Object Oriented Programming
6
Struct with blocked data unblocked
access to the data
If you took a struct from the C
programming language and made the
following changes
- allow storage fields to be blocked from
being set/modify/read from outside the
struct.
- provide functions/methods that can
set/modify/read the storage and are
unblocked to users as part of the struct.
struct baseballPlayer
{
blocked struct person info;
blocked char team[20];
blocked float battingAverage;
unblocked void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
7
Struct with blocked data unblocked
access to the data
bbp1.battingAverage = 0.325; // not allowed
bbp1.setAvg(0.325); // allowed
bbp1.setAvg(-0.325); // allowed but does nothing
struct baseballPlayer
{
blocked struct person info;
blocked char team[20];
blocked float battingAverage;
unblocked void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
8
Pseudo-C(1972) vs. C++(1985)
struct baseballPlayer
{
blocked struct person info;
blocked char team[20];
blocked float battingAverage;
unblocked void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
class baseballPlayer
{
private person info;
private char team[20];
private float battingAverage;
public void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
9
Classes vs. Objects
A person is a Classification (Class for short)
A baseball player is a Classification
Joe DiMaggio is an instance of a person (and so are you) and an instance of a baseball player.
Baseball player is the class (description (data fields) and functionality (methods))
Joe DiMaggio is an object (i.e. instance of a baseball player). So is Mickey Mantle.
10
Composition vs. Inheritance
class baseballPlayer
{
private person info;
private char team[20];
private float battingAverage;
public void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
Here the class baseball player is
composed of a person, plus additional
information related to baseball players.
If you had a baseballPlayer object bbp1,
the access the firstName, you use
Print(bbp1.info.firstName).
Why do we need info? Because a
baseball player is composed of an
person object we called info plus other
stuff.
This is called composition.
11
Composition vs. Inheritance
class baseballPlayer
{
private person info;
private char team[20];
private float battingAverage;
public void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
class baseballPlayer::public person
{
private char team[20];
private float battingAverage;
public void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
bbp1.firstName = “Joe”;
bbp1.info.firstName = “Joe”;
12
Construction (initialization) of an object
int x; // what value would the primitive variable x be set to? 0? NaN?
String s: // what value should the string be set to?
baseballPlayer bbp1; // what values should the firstName, lastNAme, battingAverage be set to?
The programming language may have default values to set uninitialized data to.
But the programming language doesn’t know have to initialize class (user defined) data.
Solution: a Constructor function which runs when the object first created
13
Example of a Constructor function
Class fraction {
private int numerator;
private int denominator;
public fraction()
{
numerator = 0; //
denominator = 1; // avoid divide by zero accident
}
}
14
Class vs object variables
Object variable are variables that each
object has. Each baseball player has a
firstName, a batting average etc. These
are called object variables.
A class may have a variable that is
shared by all objects of the class. Like
NumOfPlayers.
A static variable (class variable) is
shared be all objects of the class.
class baseballPlayer::public person
{
private char team[20];
private float battingAverage;
static private int NumOfPlayers = 0;
public void setAvg(float a)
{
if (a =< 1) && (a>=0) { battingAverage = a; }
}
}
15
Mathematics vs. Applied Mathematics
1 + 1 = 2 is mathematics
1 banana + 1 banana = 2 bananas is applied mathematics
Is 1 banana + 1 apple = 2 bananas? Answer: no apples are not bananas.
Is 1 fruit + 1 apple = 2 fruits? Answer: yes because apple is fruit
Is 1 fruit + 1 apple = 2 apples? Answer: maybe because the fruit may or may not be an apple
Is an apple composed of a fruit plus additional apple attributes? Answer: no it’s inherently fruit
16
4 Pillars of Object Oriented Programming
17

More Related Content

Similar to classes.pptx

Structures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptxStructures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptx
ShreevatsaAlawandi
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
Epsiba1
 
JavaTalks: OOD principles
JavaTalks: OOD principlesJavaTalks: OOD principles
JavaTalks: OOD principles
stanislav bashkirtsev
 
Op ps
Op psOp ps
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
sdrhr
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
Intro C# Book
 
slideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdfslideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdf
HimanshuKansal22
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
Muhammad Hammad Waseem
 
Type level programming in Scala
Type level programming in ScalaType level programming in Scala
Type level programming in Scala
Ikhoon Eom
 
Presentation
PresentationPresentation
Presentation
manogallery
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
FALLEE31188
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdf
LadallaRajKumar
 
Constructors and destructors in C++
Constructors and destructors in  C++Constructors and destructors in  C++
Constructors and destructors in C++
RAJ KUMAR
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
SantoshVarshney3
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
aggarwalshoppe14
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
Lovely Professional University
 
Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
Lovely Professional University
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
SIMONTHOMAS S
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
Intro C# Book
 

Similar to classes.pptx (20)

Structures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptxStructures_Final_KLE (2).pptx
Structures_Final_KLE (2).pptx
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
 
JavaTalks: OOD principles
JavaTalks: OOD principlesJavaTalks: OOD principles
JavaTalks: OOD principles
 
Op ps
Op psOp ps
Op ps
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
 
14 Defining Classes
14 Defining Classes14 Defining Classes
14 Defining Classes
 
slideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdfslideset 7 structure and union (1).pdf
slideset 7 structure and union (1).pdf
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
Type level programming in Scala
Type level programming in ScalaType level programming in Scala
Type level programming in Scala
 
Presentation
PresentationPresentation
Presentation
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdf
 
Constructors and destructors in C++
Constructors and destructors in  C++Constructors and destructors in  C++
Constructors and destructors in C++
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Class and object C++.pptx
Class and object C++.pptxClass and object C++.pptx
Class and object C++.pptx
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2Constructors and destructors in C++ part 2
Constructors and destructors in C++ part 2
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 

More from MattMarino13

1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx
MattMarino13
 
1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx
MattMarino13
 
BITM3730 11-14.pptx
BITM3730 11-14.pptxBITM3730 11-14.pptx
BITM3730 11-14.pptx
MattMarino13
 
01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx
MattMarino13
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
MattMarino13
 
Hoisington_Android_4e_PPT_CH01.pptx
Hoisington_Android_4e_PPT_CH01.pptxHoisington_Android_4e_PPT_CH01.pptx
Hoisington_Android_4e_PPT_CH01.pptx
MattMarino13
 
AndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxAndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptx
MattMarino13
 
9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx
MattMarino13
 
krajewski_om12 _01.pptx
krajewski_om12 _01.pptxkrajewski_om12 _01.pptx
krajewski_om12 _01.pptx
MattMarino13
 
CapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptxCapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptx
MattMarino13
 
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptxProject Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
MattMarino13
 
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptxProject Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
MattMarino13
 
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
MattMarino13
 
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
MattMarino13
 
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
MattMarino13
 
1-23-19 Agenda.pptx
1-23-19 Agenda.pptx1-23-19 Agenda.pptx
1-23-19 Agenda.pptx
MattMarino13
 
EDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptxEDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptx
MattMarino13
 
Agenda January 20th 2016.pptx
Agenda January 20th 2016.pptxAgenda January 20th 2016.pptx
Agenda January 20th 2016.pptx
MattMarino13
 
BITM3730 8-29.pptx
BITM3730 8-29.pptxBITM3730 8-29.pptx
BITM3730 8-29.pptx
MattMarino13
 
BITM3730 8-30.pptx
BITM3730 8-30.pptxBITM3730 8-30.pptx
BITM3730 8-30.pptx
MattMarino13
 

More from MattMarino13 (20)

1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx1-22-24 INFO 2106.pptx
1-22-24 INFO 2106.pptx
 
1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx1-24-24 INFO 3205.pptx
1-24-24 INFO 3205.pptx
 
BITM3730 11-14.pptx
BITM3730 11-14.pptxBITM3730 11-14.pptx
BITM3730 11-14.pptx
 
01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx01_Felke-Morris_Lecture_ppt_ch01.pptx
01_Felke-Morris_Lecture_ppt_ch01.pptx
 
02slide_accessible.pptx
02slide_accessible.pptx02slide_accessible.pptx
02slide_accessible.pptx
 
Hoisington_Android_4e_PPT_CH01.pptx
Hoisington_Android_4e_PPT_CH01.pptxHoisington_Android_4e_PPT_CH01.pptx
Hoisington_Android_4e_PPT_CH01.pptx
 
AndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptxAndroidHTP3_AppA.pptx
AndroidHTP3_AppA.pptx
 
9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx9780357132302_Langley11e_ch1_LEAP.pptx
9780357132302_Langley11e_ch1_LEAP.pptx
 
krajewski_om12 _01.pptx
krajewski_om12 _01.pptxkrajewski_om12 _01.pptx
krajewski_om12 _01.pptx
 
CapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptxCapsimOpsIntroPPT.Marino.pptx
CapsimOpsIntroPPT.Marino.pptx
 
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptxProject Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
Project Presentation_castroxa_attempt_2021-12-05-18-30-10_No Cap.pptx
 
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptxProject Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
Project Presentation_mirzamad_attempt_2021-12-05-23-35-25_HTML_presentation.pptx
 
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
Project Presentation_padillni_attempt_2021-12-05-18-52-37_Web Application Pre...
 
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
Project Presentation_thomasb1_attempt_2021-12-05-17-50-13_Developing Web Apps...
 
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
Project Presentation_hernana1_attempt_2021-12-05-22-06-56_Miyamoto BITM 3730 ...
 
1-23-19 Agenda.pptx
1-23-19 Agenda.pptx1-23-19 Agenda.pptx
1-23-19 Agenda.pptx
 
EDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptxEDF 8289 Marino PPT.pptx
EDF 8289 Marino PPT.pptx
 
Agenda January 20th 2016.pptx
Agenda January 20th 2016.pptxAgenda January 20th 2016.pptx
Agenda January 20th 2016.pptx
 
BITM3730 8-29.pptx
BITM3730 8-29.pptxBITM3730 8-29.pptx
BITM3730 8-29.pptx
 
BITM3730 8-30.pptx
BITM3730 8-30.pptxBITM3730 8-30.pptx
BITM3730 8-30.pptx
 

Recently uploaded

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
khuleseema60
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 

Recently uploaded (20)

Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025MDP on air pollution of class 8 year 2024-2025
MDP on air pollution of class 8 year 2024-2025
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 

classes.pptx

  • 1. Classes (and Objects) CLASSES AND OBJECTS MADE FROM THEM INHERITANCE, INTERFACES 1
  • 3. Non-primitive types Arrays – a named structure of primitive/non-primitive indexed by an integer value Strings – a collection of characters User defined Structure and Classes 3
  • 4. User defined structures (C language) struct person { char firstName[20]; char lastName[20]; int dob_year; } struct baseballPlayer { struct person info; char team[20]; float battingAverage; } Here a person is a classification of how to capture data about a person. A baseballPlayer is a classification is a special type of person. Should the programming language define a Baseball Player for all users (application developers) to have to use or should the language allow the user to define a Baseball Player however they want. 4
  • 5. Creating and Initializing an instance of a structure (classification), and print struct person p1 = { “Joe”, ”Smith”, 1990 }; struct baseballPlayer bbp1 = { {“Joe”,”Dimaggio”,1914 } “Yankees”, 0.325 }; printf("Name: %sn", bbp1.info.firstName); printf("Name: %sn", p1.firstName); 5
  • 6. Modifying structure data What if the DOB_year was set to 3030? What if the baseball player’s team was set to “Rams”? What if the baseball player’s batting average was set to -0.325? or 11.234 or “Jello”. What if the person’s last name is “” ( ie Blank) What if a program over-wrote an array and destroyed data in a structure? Solution: Object Oriented Programming 6
  • 7. Struct with blocked data unblocked access to the data If you took a struct from the C programming language and made the following changes - allow storage fields to be blocked from being set/modify/read from outside the struct. - provide functions/methods that can set/modify/read the storage and are unblocked to users as part of the struct. struct baseballPlayer { blocked struct person info; blocked char team[20]; blocked float battingAverage; unblocked void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } 7
  • 8. Struct with blocked data unblocked access to the data bbp1.battingAverage = 0.325; // not allowed bbp1.setAvg(0.325); // allowed bbp1.setAvg(-0.325); // allowed but does nothing struct baseballPlayer { blocked struct person info; blocked char team[20]; blocked float battingAverage; unblocked void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } 8
  • 9. Pseudo-C(1972) vs. C++(1985) struct baseballPlayer { blocked struct person info; blocked char team[20]; blocked float battingAverage; unblocked void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } class baseballPlayer { private person info; private char team[20]; private float battingAverage; public void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } 9
  • 10. Classes vs. Objects A person is a Classification (Class for short) A baseball player is a Classification Joe DiMaggio is an instance of a person (and so are you) and an instance of a baseball player. Baseball player is the class (description (data fields) and functionality (methods)) Joe DiMaggio is an object (i.e. instance of a baseball player). So is Mickey Mantle. 10
  • 11. Composition vs. Inheritance class baseballPlayer { private person info; private char team[20]; private float battingAverage; public void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } Here the class baseball player is composed of a person, plus additional information related to baseball players. If you had a baseballPlayer object bbp1, the access the firstName, you use Print(bbp1.info.firstName). Why do we need info? Because a baseball player is composed of an person object we called info plus other stuff. This is called composition. 11
  • 12. Composition vs. Inheritance class baseballPlayer { private person info; private char team[20]; private float battingAverage; public void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } class baseballPlayer::public person { private char team[20]; private float battingAverage; public void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } bbp1.firstName = “Joe”; bbp1.info.firstName = “Joe”; 12
  • 13. Construction (initialization) of an object int x; // what value would the primitive variable x be set to? 0? NaN? String s: // what value should the string be set to? baseballPlayer bbp1; // what values should the firstName, lastNAme, battingAverage be set to? The programming language may have default values to set uninitialized data to. But the programming language doesn’t know have to initialize class (user defined) data. Solution: a Constructor function which runs when the object first created 13
  • 14. Example of a Constructor function Class fraction { private int numerator; private int denominator; public fraction() { numerator = 0; // denominator = 1; // avoid divide by zero accident } } 14
  • 15. Class vs object variables Object variable are variables that each object has. Each baseball player has a firstName, a batting average etc. These are called object variables. A class may have a variable that is shared by all objects of the class. Like NumOfPlayers. A static variable (class variable) is shared be all objects of the class. class baseballPlayer::public person { private char team[20]; private float battingAverage; static private int NumOfPlayers = 0; public void setAvg(float a) { if (a =< 1) && (a>=0) { battingAverage = a; } } } 15
  • 16. Mathematics vs. Applied Mathematics 1 + 1 = 2 is mathematics 1 banana + 1 banana = 2 bananas is applied mathematics Is 1 banana + 1 apple = 2 bananas? Answer: no apples are not bananas. Is 1 fruit + 1 apple = 2 fruits? Answer: yes because apple is fruit Is 1 fruit + 1 apple = 2 apples? Answer: maybe because the fruit may or may not be an apple Is an apple composed of a fruit plus additional apple attributes? Answer: no it’s inherently fruit 16
  • 17. 4 Pillars of Object Oriented Programming 17