Class Notes (1,100,000)
CA (650,000)
Western (60,000)
ENGSCI (100)
Lecture 8

Engineering Science 1036A/B Lecture Notes - Lecture 8: Object-Oriented Programming, Global Variable, Memory Management


Department
Engineering Science
Course Code
ENGSCI 1036A/B
Professor
Quazi Rahman
Lecture
8

This preview shows pages 1-3. to view the full 20 pages of the document.
Class and Objects
Classes:
A class is a mechanism that allows a programmer to define new
data types by following the object oriented programming
principles
A class can be used:
To add functionality to an existing data type or
To create a new data type
A class definition combines data and functionality
Class analogy:
Class Declaration Syntax:
class valid_data_type_name
{
data members and function members are declared here.
We can not initialize any data members here
}
find more resources at oneclass.com
find more resources at oneclass.com

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Class Declaration Syntax Cont. :
Also included in the body of a class is a member access
privilege label
Example:
When a class contains function members, we need
to define those functions before we use the
class to create a new data type
In
general, defining the member functions of a class is known as
‘Class definition’
The member functions can be defined within the class
declaration segment, and in this case, it is called in-line
declaration as shown below:
Objects in Classes:
An object is a variable of a defined class type, also referred to as
an instance of a class
Example: If ‘Student’ is a class then objects can be declared as:
find more resources at oneclass.com
find more resources at oneclass.com

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Student Adam;
Student Eve;
In the above example, the objects Eve and Adam contains all the
characteristics declared in the class Student, which can be
accessed via member access operator
Data type and Variable Name:
The relationship between class and object is equivalent to the
relationship between data-type and variable-name
Declaring an object of class ‘Student’ follows similar approach of
declaring a variable of ‘int’ type data as shown
Data type and Variable Name Cont. :
Student x; // x is the name of an object of Student type
Int y; //y is a name of a variable of int type
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview

Unlock to view full version