You are on page 1of 70

DITP 2113 Struktur Data & Algoritma

Lecture 1: Class & Object


Objective:
 To introduce Class and Object concepts.
 To introduce the constructor, destructor and access modifiers.
 To introduce the concepts of inheritance, overloading and
overriding.
 To assure that students are able to apply the concepts in the
program.
 To assure that students are able to increase their expertise on
the topics.
Class & Object
 A class is a combination of structure and function prototype.
 The major difference:
 The variable declared as a Class is an object.
 An object is an instance of the class.
 A class is created to show a global picture of real world or
the environment that interact to each other.
 For example : A CAR. When thinking about cars :
 Things to construct cars (attribute): tires, doors, seats.
 Things that cars can do (behavior): speeding, stop.
 A class will have their own attribute and behavior that can
interact with other classes.
 A class is like a ‘blueprint’ for a house.

2
Class & Object
 Data hiding : it is implemented by combining the data and
operations into an object.
 The data in the class are physically located inside the class
object and therefore can be hidden from the application
program.
 It cannot be accessed or changed except by functions
or methods that are part of the class.
 Data hiding is important to ensure the data integrity.
 A class is able to encapsulate the data structure and the
data operations inside the class (as one entity or collection)
and only allow access through controlled methods.

3
Class & Object
 Encapsulation has several advantages:
 Easy to access any information regarding the class.
 Any other classes that need to interact with the class
doesn’t need to know about what’s inside the class
or how it works.
 A class describes the attributes that each object includes
as a variable and it is also known as data member.
 For example: name, age, accountNum, numOfTyre
 A class describes the behaviors (operations) that each
object exhibits through functions or methods.
 For example: setAccount(), getAge(), calcAve()
 The functions will use the data members in its operations.

4
Access Specifiers
There are three access specifiers that can be used with
either the class member data or the member functions
(methods).
 private: the data or functions can only be accessed by
the member of the class
 public: the data or functions can be accessed by the
member of the class and other classes
 protected: the data or functions can be accessed by
the member of the class and its subclasses

 The default access specifiers is private.

5
Access Specifiers

Modifier Same Same Sub universe


Class Package class
private yes

protected yes yes yes

public yes yes yes yes

6
Class Declaration
 Class Declaration Syntax
class ClassName {
private:
//private attribute and method();
public:
//public attribute and method();
};

 Example:
class Fraction {
private:
int numerator;
int denominator;
public:
void store (int numer, int denom);
void print ();
};

7
Object Declaration
 Defining an object of a class type is called instantiation.
 Each instance of a class is known as an object.
 Object Declaration Syntax :
Class_Name object_Name;

 Example: Fraction frac;

 When an object is declared, a dot notation is required to


access the data member or methods.
 Example using dot notation:
Fraction frac;
frac.numerator = 15;
frac.store(numerator, denominator);

8
Object Declaration
 Scope resolution operator ‘::’ is used when an identifier
that is referred to is not within the current scope.
 For example, the function definition is defined outside of
the class.
 Therefore, it is needed to use scope resolution operator to
specify that the function is belong to the class.
 Syntax Declaration: Class_Name :: member_name
 Example:
void Fraction :: store (int numer, int denom)
{ }

9
Program Example
Example: Creating a class and using object to refer to data member and
functions.
#include<iostream>
using namespace std;
//Header file for simple Fraction class.
class Fraction {
private:
int numerator;
int denominator;
public:
void store (int numer, int denom);
void print () const;
};
//Methods definition
void Fraction :: store (int numer, int denom) {
numerator = numer;
denominator = denom;
}
void Fraction :: print () const {
cout << numerator << “/” << denominator;
} 10
Program Example
Example: Creating a class and using object to refer to data member and
functions (cont).
//Create object and use Fraction class.
int main() {
int numer;
int denom;
Fraction frac;
cout << “This program creates a fraction\n”;
cout << “Please enter the numerator: ”;
cin >> numer;
cout << “Please enter the denominator: ”
cin >> denom;
frac.store(numer, denom);
cout << “\nYour fraction contains: ”;
frac.print();
return 0;
}

11
Program Example
Example: Creating a class and using object to refer to data member and
functions (cont).

Output : This program creates a fraction


Please enter the numerator: 19
Please enter the denominator: 51
Your fraction contains: 19/51

 The data member of the class is usually private. This is


to assure the data integrity. In order to access the data,
the class should have the set() and get() method to
control data usage.
 The methods of the class is usually public and accessible
to the member of the class and other classes.
12
Constructor & Destructor
 Constructors are special member functions that are called
when an instance of a class is created.
Fraction frac1;
Fraction frac2(3);
Fraction frac3(3,4);

 A class may have more than one constructor.


 An overloaded constructor is implemented with more than
one constructor.
 Each constructor initializes data members differently.
 Constructors have three uses:
 Initializes data member when required.
 Use to validate data and make the program more robust.
 Use to allocate memory for an object.
13
Constructor & Destructor
 Constructors follow two basic rules:
 Its name is the same as the class name.
 It must not have any return type, even void.
 Constructor Declaration Syntax:
Class_Name (parameter list);
 Example:
Fraction (int numem, int denom);
 Constructor Definition:
Class_Name :: Class_Name (parameter list)
{ }
 Example:
Fraction :: Fraction (int numem, int denom)
{ }
14
Constructor & Destructor
 A class must have at least one constructor, either defined by
the program or by the compiler.
 A default constructor has no parameter. It is called whenever
an object is created without passing any arguments.
 If the programmer doesn’t provide any constructors, the
compiler provides a default constructor.
 If the programmer define any type of constructor, then
the programmer also needs to define a default
constructor.
 Example:
Fraction :: Fraction ()
{ }

15
Constructor & Destructor
 Destructor are the opposite of constructors. It is used
when the object dies, either because it is no longer in
scope or it has been deleted.
 A destructor cannot have a return type.
 The argument list of the destructor must be empty.
 It cannot be overloaded.
 The name of the destructor is the name of the class
preceded by a tilde (~).
Class_Name :: ~Class_Name() { }
 A class must have one and only one destructor.
 A destructor usually is a default destructor. It does nothing.
 But if there is a class uses dynamic memory allocation, it is
needed to release memory in the destructor.
16
Program Example
Example: Creating a class and using object to refer to constructors.
#include<iostream>
using namespace std;
//Fraction class declaration. –Filename: Fraction.cpp
class Fraction {
private:
int numerator;
int denominator;

public:
Fraction ();
Fraction (int numer);
Fraction (int numer, int denom);
~Fraction() { } //destructor
void print () const;
};

void Fraction :: print () const {


cout << numerator << “/” << denominator;
}
17
Program Example
Example: Creating a class and using object to refer to constructors (cont).
//Constructor definition – without parameter
Fraction :: Fraction () {
numerator = 0;
denominator = 1;
}

//Constructor definition – 1 parameter


Fraction :: Fraction (int numen) {
numerator = numen;
denominator = 1;
}

//Constructor definition – 2 parameter


Fraction :: Fraction (int numen, int denom) {
numerator = numen;
denominator = denom;
}
18
Program Example
Example: Creating a class and using object to refer to constructors (cont).
//Create object and use Fraction class constructors.
int main() {
Fraction frac1;
cout << “Fraction 1 contains: ”;
frac1.print();
cout << endl;

Fraction frac2 (4);


cout << “Fraction 2 contains: ”;
frac2.print();
cout << endl;

Fraction frac3 (5,8);


cout << “Fraction 3 contains: ”;
frac3.print();
cout << endl;
return 0;
}

19
Program Example
Example: Creating a class and using object to refer to constructors (cont).

Output : Fraction 1 contains: 0/1


Fraction 2 contains: 4/1
Fraction 3 contains: 5/8

20
Mutators & Accessors
 The data member of the class is usually private. This is
to assure the data integrity. In order to access the data,
the class should have certain method to control data
usage.
 The methods of the class is usually public and accessible
to the member of the class and other classes.
 There are two types of functions:
 Mutator Functions
 Accessor Functions

 A mutator is a function that can change the state of a host


object, the object that invokes it.
 It is also known as the set() methods.

21
Mutators & Accessors
 An accessor is a function that cannot change the state of
its invoking object.
 It is called either for its side effects such as to print or for
its return value.
 Accessor must always have a return type.
 By adding the keyword const is to ensure that an accessor
does not change the state of the host object.
 It is also known as the get() method.

22
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods.
//Account class declaration. – Filename: Account.cpp
#include <iostream>
#include <iomanip>
using namespace std;

class Account {
private:
double balance;

public:
Account ();
double getBalance () const;
void deposit (double amount);
void withdraw (double amount);
};

23
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods (cont).
//Constructor definition – without parameter
Account :: Account () {
balance = 0.0;
}

double Account :: getBalance () const {


return balance;
}

void Account :: deposit (double amount) {


balance += amount;
}

void Account :: withdraw (double amount) {


balance -= amount;
}
24
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods (cont).
//Create object and use Account class methods.
int main() {

Account acc;

cout << “Your account balance is : ”


<< setw(5) << acc.getBalance() << endl;

acc.deposit(100.0);
cout << “Your account balance is : ”
<< setw(5) << acc.getBalance() << endl;

acc.withdraw(50.0);
cout << “Your account balance is : ”
<< setw(5) << acc.getBalance() << endl;
return 0;
}

25
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods(cont).

Output : Your account balance is: 0


Your account balance is: 100
Your account balance is: 50

26
Interface & Implementation
 The separation of program interface and its implementation
will ease of the programmer to read or change the program.

 What is a program interface?


 An interface is a declaration of class, data members,
constructors, and methods prototype.
 It is also known as the class header.

 What is the program implementation?


 The implementation is the program that define and
execute the class declaration in some methods or
method main().

27
Interface & Implementation
 The class declaration is usually kept in the header files
(.h or .hpp) while the definition for methods is kept in a
source files (.cpp) that usually has the same name as the
header.
 The class implementation is kept in another source files
(.cpp). It has to include all classes needed.

28
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods.

//Class declaration – Filename: Account_v2.h


#ifndef ACCOUNT_V2_H
#define ACCOUNT_V2_H
class Account {
private:
double balance;

public:
Account ();
double getBalance () const;
void deposit (double amount);
void withdraw (double amount);
};
#endif

29
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods (cont).

//Source files – Filename: Account_v2.cpp


#include “Account_v2.h”

Account :: Account () {
balance = 0.0;
}
double Account :: getBalance () const {
return balance;
}
void Account :: deposit (double amount) {
balance += amount;
}
void Account :: withdraw (double amount) {
balance -= amount;
}
30
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods (cont).
//Program implementation – Filename: AccountMain.cpp
#include <iostream>
#include <iomanip>
#include “Account.h”
using namespace std;

int main() {
Account acc;
cout << “Your account balance is : ”
<< setw(5) << acc.getBalance() << endl;
acc.deposit(100.0);
cout << “Your account balance is : ”
<< setw(5) << acc.getBalance() << endl;
acc.withdraw(50.0);
cout << “Your account balance is : ”
<< setw(5) << acc.getBalance() << endl;
return 0;
}
31
Program Example
Example: Maintain a bank account balance using deposit and withdraw
methods(cont).

Output : Your account balance is: 0


Your account balance is: 100
Your account balance is: 50

32
Interface & Implementation
 The preprocessor code as shown in the example:
#ifndef ACCOUNT_H
#define ACCOUNT_H
….
#endif

 #ifndef means if not define.


 These three codes are included to assure that the header
file is not being defined repeatedly during the program
implementation.

33
Using other class members
 A class (base class) that always being used by other
classes needs to avoid using access specifier private for
its members.
 The accessibility for data member is usually a private.
 The solution for this is by using the access specifier
protected to allow the derived classes to use the data
member from the base class.
 The derived class is allowed to use all protected and public
data member and methods from the base class.
 This concepts is also known as inheritance.

34
Program Example
Example: Using protected for data member

//Class declaration – Filename: Account_v3.h


#ifndef ACCOUNT_V3_H
#define ACCOUNT_V3_H

class Account {
protected:
int accNum;
char *name;

public:
Account ();
double openAcc (const int, const char*);
void printAcc ();
};
#endif

35
Program Example
Example: Using protected for data member (cont).
//Source files – Filename: Account_v3.cpp
#include <iostream>
#include <cstring>
#include “Account_v3.h”

Account :: Account () {
accNum = 0;
strcpy(name, “”);
}
void Account :: openAcc (const int num, const char *pname)
{
accNum = num;
strcpy(name, pname);
}
void Account :: printAcc () {
cout << “Account Number: ” << accNum << endl;
cout << “Name : ” << name << endl;
}
36
Program Example
Example: Using protected for data member (cont).

//Class declaration – Filename: Current.h


#ifndef CURRENT_H
#define CURRENT_H

class Current : public Account {


private:
double balance;

public:
Current ();
void deposit (const double);
void printBalance ();
};
#endif

37
Program Example
Example: Using protected for data member (cont).
//Source files – Filename: Current.cpp
#include <iostream>
#include “Account_v3.h”
#include “Current.h”
using namespace std;

Current :: Current () {
balance = 0.0
}
void Current :: deposit (const double dep) {
balance += dep;
}
void Current :: printBalance () {
cout << “From current Account:\n”;
cout << “Current Account Number: ” << accNum << endl;
cout << “Name : ” << name << endl;
cout << “Balance account: ” << balance << endl;
}
38
Program Example
Example: Using protected for data member (cont).
//Program implementation – Filename:
CurrentAccountMain.cpp
#include “Account_v3.h”
#include “Current.h”
using namespace std;

int main() {
Current acc;
acc.openAcc(111, “Milah”);
acc.printAcc();
acc.deposit(1000.0);
acc.printBalance();
acc.deposit(50.0);
acc.printBalance();
return 0;
}

39
Program Example
Example: Using protected for data member (cont).

Output : Account Number: 111


Name: Milah
From current account:
Current Account Number: 111
Name: Milah
Balance Account: 1000
From current account:
Current Account Number: 111
Name: Milah
Balance Account: 1050

40
Overloading
 Overloading is the definition of two or more methods using
the same name.
 Every methods must have different parameters.
 The compiler will recognize the methods from its different
parameters and signature.
 Example:
void calcAve(); //return nothing, no parameter
void calcAve(int num); //return nothing, 1 parameter
int calcAve(int n, int s); //return integer, 2 parameter

41
Program Example
Example: Calculate average for numbers.

//Class declaration – Filename: Average.h


#ifndef AVERAGE_H
#define AVERAGE_H
class Average {
private:
int a, b;
double c, d, e;

public:
Average ();
~Average ();
void calculate (int, int);
void calculate (double, double, double);
};
#endif

42
Program Example
Example: Calculate average for numbers (cont).

//Source files – Filename: Average.cpp


#include <iostream>
#include “Average.h”
using namespace std;

Average :: Average () {}
Average :: ~Average () {}

void Average :: calculate (int m, int n) {


a = m;
b = n;
cout << “Average integer: ” << (a+b)/2 << endl;
}
void Average :: calculate (double x, double y, double z) {
c = x;
d = y;
e = z;
cout << “Average double: ” << (c+d+e)/3 << endl;
}
43
Program Example
Example: Calculate average for numbers (cont).

//Program implementation – Filename: AverageMain.cpp


#include “Average.h”

int main() {
Average avei, aved;
avei.calculate(4,4);
aved.calculate(2.5,2.5,2.5);
return 0;
}

Output: Average integer: 4


Average double: 2.5

44
Overloading
 Program Description:
The calculate() method will be called according to
its equivalent parameter with the data send by its caller.
From the program, object avei will call the first
calculate() method that will receive two integers
while object aved will call the second calculate()
method that has three double parameters.

 The constructors can be overloaded too:


Average(); //no parameter
Average(int num); //1 integer parameter
Average(int n, int s); //2 integer parameter
Average(double q, double p) //2 double parameter

45
Program Example
Example: Calculate total for numbers.

//Class declaration – Filename: Addition.h


#ifndef ADDITION_H
#define ADDITION_H
class Addition {
private:
int x, y;

public:
Addition ();
Addition(int);
Addition(int, int);
~Addition ();
void calculate ();
};
#endif

46
Program Example
Example: Calculate total for numbers (cont).
//Source files – Filename: Addition.cpp
#include “Addition.h”
#include <iostream>
using namespace std;
Addition :: Addition () {
x = y = 0;
}
Addition :: Addition (int a) {
x = a;
y = 1;
}
Addition :: Addition(int x1, int y1) {
x = x1;
y = y1;
}
Addition :: ~Addition() { }

void Addition :: calculate () {


cout << “Total: ” << x+y << endl;
}
47
Program Example
Example: Calculate total for numbers (cont).

//Program implementation – Filename: AdditionMain.cpp


#include “Addition.h”

int main() {
Addition tot, total(1), sum(2,2);
tot.calculate();
total.calculate();
sum.calculate();
return 0;
}

Total: 0
Output: Total: 2
Total: 4

48
Overriding
 Overriding allow the programmer to change the program
implementation in the base class to be included and use in the
derived class.
 When the object is created for the derived class, the current
method inside the derived class will be called rather than the
original method in the base class.
 The override method must have the same name with the
original method but it doesn’t necessary to have the same
signature or function prototype.
 The implementation of the override method can be different
or not.

49
Overriding
 The difference between overloading and overriding:
 The overloading concepts happens in the same class.
 The overriding concepts happens between two different
classes that are the base class and its derived classes.

50
Program Example
Example: Overriding method.

//Class declaration - Filename: Mammal.h


#ifndef MAMMAL_H
#define MAMMAL_H
class Mammal {
protected:
int age;
double weight;

public:
Mammal ();
~Mammal ();
void setAgeWeight (int, double);
void sleep (); //original method
void eat ();
};
#endif
51
Program Example
Example: Overriding method (cont).
//Source files – Filename: Mammal.cpp
#include “Mammal.h”
#include <iostream>
using namespace std;
Mammal :: Mammal () { }
Mammal :: ~Mammal () { }
void Mammal :: setAgeWeight(int a, double w) {
age = a;
weight = w;
}
void Mammal :: sleep() {
cout << “At the age of ” << age
<< “ years old I like to sleep.\n”;
cout << “Shhhhhhh\n” << endl;
}
void Mammal :: eat () {
cout << “I eat until my weight reach ”
<< weight << endl;
}

52
Program Example
Example: Overriding method (cont).

//Class declaration - Filename: Cat.h


#ifndef CAT_H
#define CAT_H
class Cat : public Mammal {
public:
Cat ();
~Cat ();
void sleep (); //override method
};
#endif

53
Program Example
Example: Overriding method (cont).
//Source files – Filename: Cat.cpp
#include “Mammal.h”
#include “Cat.h”
#include <iostream>
using namespace std;
Cat :: Cat () { }
Cat :: ~Cat () { }

//the override method has a different implementation


//from the original method
void Cat :: sleep() {
cout << “I have slept all the year until I am ” << age
<< “ years old\n”;
cout << “My favorite hobby is sleeping” << endl;
}

54
Program Example
Example: Override method (cont).

//Program implementation – Filename: CatMain.cpp


#include <iostream>
#include “Mammal.h”
#include “Cat.h”
using namespace std;

int main() {
Mammal Dino;
Cat Siti;
Dino.setAgeWeight(400, 1050.34);
Siti.setAgeWeight(12,25.6);
cout << “The original method sleep\n”;
Dino.sleep();
cout << “The override method sleep\n”;
Siti.sleep();
return 0;
}

55
Program Example
Example: Override method (cont).

Output: The original method sleep


At the age of 400 years old, I like to sleep
Shhhhhhh
The override method sleep
I have slept all the year until I am 12 years old
My favorite hobby is sleeping

 The derived class object can call the original method by:
derived_class_object.Base_Class_Name::method();

 Example:
Siti.Mammal::sleep();
56
Friend
 A class can grant friend status to a nonmember function or
to another class. All member functions of the class granted
friendship have unrestricted access to the members of the
class granting the friendship.
 Class friendship is not reciprocal; the member functions of
the class granting friendship cannot access the members of
the friend class.
 Class friendship is granted in the prototype declarations of
the granting class.
class FirstClass {
friend class SecondClass;
private:
………
}
57
Friend
 The programmer can use the friend concept to allow other
classes to access private data members or functions.
 For example, class B use friend concept to access data from
class A. Class A will grant the friendship to class B. All data
members or functions in class A will be public to Class B.
 Friend can not be transferred or inherited.
 For example, although Siti and Minah is a friend while Siti is
also a friend to Dayang but doesn’t mean that Minah and
Dayang is a friend.
 Another example, although Siti and Minah share secrets
together doesn’t mean that Siti wants to share the secrets with
Minah’s children.

58
Program Example
Example: Friend concept.

//Class declaration – Filename: FirstClass.h


#ifndef FIRSTCLASS_H
#define FIRSTCLASS_H
class FirstClass {
friend class SecondClass; //friend to FirstClass
private:
int x;

public:
FirstClass ();
~FirstClass ();
void setX (int);
void printData ();
};
#endif

59
Program Example
Example: Friend concept (cont).
//Source files – Filename: FirstClass.cpp
#include “FirstClass.h”
#include <iostream>
using namespace std;

FirstClass :: FirstClass () {
x = 5;
}

FirstClass :: ~FirstClass () { }

void FirstClass :: setX(int a) {


x = a;
}

void FirstClass :: printData() {


cout << “X value is: ” << x << endl;
}
60
Program Example
Example: Friend concept (cont).

//Class declaration – Filename: SecondClass.h


#ifndef SECONDCLASS_H
#define SECONDCLASS_H
class FirstClass; //forward declaration
class SecondClass {
private:
int y;
public:
SecondClass ();
~SecondClass ();
void print (FirstClass);
};
#endif

61
Program Example
Example: Friend concept (cont).
//Source files – Filename: SecondClass.cpp
#include “SecondClass.h”
#include “FirstClass.h”
#include <iostream>
using namespace std;

SecondClass :: SecondClass () {
y = 2;
}

SecondClass :: ~SecondClass () { }

void SecondClass :: print (FirstClass yc) {


cout << “Y value is ” << y + yc.x
<< endl;
}

62
Program Example
Example: Friend concept (cont).

//Program implementation – Filename: SecondMain.cpp


#include <iostream>
#include “FirstClass.h”
#include “SecondClass.h”
using namespace std;

int main() {
SecondClass S;
FirstClass M;
cout << “Y from Second Class\n”;
S.print(M);
M.setX(4);
cout << “X from First Class\n”;
M.printData();
cout << “Y from Second Class\n”;
S.print(M);
return 0;
}

63
Program Example
Example: Friend concept (cont).

Output: Y from Second Class


Y value is : 7
X from Second Class
X value is : 4
Y from Second Class
Y value is : 6

 A forward declaration must be made to the granted class to


acknowledge the use of the granting class:
#ifndef SECONDCLASS_H
#define SECONDCLASS_H
class FirstClass; // forward declaration
class SecondClass { … }

64
Friend Method
 Friend function are not members of a class but are
associated with the class and are given special privileges.
 The function can access the private members of the class as
though they were members. This means that it can refer to the
private data and call any private functions.
 When a function is declared to be a friend, it is called as any
other nonmember function.
 To declare that a function is a friend of a class, its prototype
declaration within the class is prefixed with the keyword friend.
class FriendClass {
friend void setX (int a);
private:
………
}
65
Program Example
Example: Friend method concept.

//Class declaration – Filename: FriendClass.h


#ifndef FRIENDCLASS_H
#define FRIENDCLASS_H
class FriendClass {
//friend method to FriendClass
friend void setX (FriendClass &, int);

private:
int x;

public:
FriendClass ();
void printData ();
};
#endif

66
Program Example
Example: Friend method concept (cont).
//Source files – Filename: FriendClass.cpp
#include “FriendClass.h”
#include <iostream>
using namespace std;

FriendClass :: FriendClass () {
x = 0;
}

// doesn’t have to put ‘FriendClass::’ in front of


// method definition
void setX(FriendClass &c, int a) {
c.x = a;
}

void FriendClass :: printData() {


cout << x << endl;
}
67
Program Example
Example: Friend method concept (cont).

//Program implementation – Filename: FriendMain.cpp


#include <iostream>
#include “FriendClass.h”
using namespace std;

int main() {
FriendClass F;
cout << “Friend.x after definition:”;
F.printData();
cout << endl;
cout << “Friend.x after friend method setX is called:”;
setX(F, 8);
F.printData();
return 0;
}

68
Program Example
Example: Friend method concept (cont).

Output: Friend.x after definition: 0


Friend.x after friend method setX is called : 8

 The friend method setX() can be used by other functions


or classes without needed to create any object to call it.

69
The End

Q&A

70

You might also like