Hands
Hands
Hands
(Informatica)
Introduction (introduzione)
2
3
VS
4
What is Object Oriented Programming?
Create an object, in code, that has certain properties and
methods
Object: Basic unit. Both data and function that operate on data
Class: Define a blueprint for an object. What an object of the class will
consist of and what operations can be performed on such an object.
5
6
7
Exercise 1: Making a car class
● https://tinyurl.com/lesson01code
8
Abstraction
● Providing only essential information to the outside world and hiding their
background details, i.e., to represent the needed information in program without
presenting the details. Well-defined objects and their hierarchical classification.
9
Encapsulation
● Place the data and the functions that work on that data in the same place. Provides
you framework to place the data and the relevant functions together in the same
object.
10
Comparison
● Like an iPhone!
11
Public, Private, Protected
12
Public, Private, Protected
13
What goes where?
14
What goes where?
● Data
Functions
15
Class in C++
16
Class in C++
17
Syntax of C++ programs
● Dot syntax: access a (public) member variable. Ex. Class Animal with Animal a
classObjectName.memberName (a.name)
● Double Colon: scope resolution operator. Used for method implementations and
classes.
18
Exercise 2: Get the car info
● https://tinyurl.com/lesson01code
19
Example class!
20
Example class!
21
Example class 2
● What is the output?
● A. 0
● B. 1
● C. 6
● D. 10
22
Example class 2
● What is the output?
● A. 0
● B. 1
● C. 6
● D. 10
23
Example class 3!
● What is the output?
● A. 0
● B. 1
● C. 6
● D. 10
24
Example class 3!
● What is the output?
● A. 0
● B. 1
● C. 6
● D. 10
25
Inheritance
26
Inheritance
27
Inheritance
● Process of forming a new class from an existing class that is from the existing
class called as base class, new class is formed called as derived class.
28
Polymorphism
29
Polymorphism
● The ability to use an operator or function in different ways in other words
giving different meaning or functions to the operators or functions is called
polymorphism.
30
Exercise
● https://tinyurl.com/lesson01code
31
Quiz time!
● What does this represent?
A. Inheritance
B. Public Private Protected
C. Classes
D. Object Oriented Programs
32
Quiz time!
● What does this represent?
A. Inheritance
B. Public Private Protected
C. Classes
D. Object Oriented Programs
33
Quiz time!
● What will print when you call h.assembleSandwich on a HotSandwich h?
34
Quiz time!
● What will print when you call h.assembleSandwich on a HotSandwich h?
35
Quiz time!
● Which of the following should be private?
36
Quiz time!
● Which of the following should be private?
37
Next time: Laboratory
38