0% found this document useful (0 votes)
55 views7 pages

Object Oriented Programming

This document discusses object oriented programming concepts in C++, including classes, objects, and access modifiers. It explains that classes allow for data hiding through public, private, and protected access modifiers. Public members can be accessed anywhere, private members only within the class, and protected members within subclasses. Objects are instances of classes that allocate memory at runtime. Classes define the structure and behavior of objects through members like variables and functions.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views7 pages

Object Oriented Programming

This document discusses object oriented programming concepts in C++, including classes, objects, and access modifiers. It explains that classes allow for data hiding through public, private, and protected access modifiers. Public members can be accessed anywhere, private members only within the class, and protected members within subclasses. Objects are instances of classes that allocate memory at runtime. Classes define the structure and behavior of objects through members like variables and functions.

Uploaded by

Abdul Mateen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Object Oriented Programming

Abdul Mateen
Lecture 02
Classes, Object, Public and Private access modifiers

Why use classes instead of structures?


Classes and structures are somewhat the same but still, they
have some differences. For example, we cannot hide data in
structures which means that everything is public and can be
accessed easily which is a major drawback of the structure
because structures cannot be used where data security is a
major concern. Another drawback of structures is that we
cannot add functions in it.
Classes in C++
Classes are user-defined data-types and are a template for
creating objects. Classes consist of variables and functions
which are also called class members.
Classes, Object, Public and Private access modifiers

Access Modifier of C++?


The access modifiers of C++ are public, private, and
protected. One of the main features of object-oriented
programming languages such as C++ is data hiding. ... The
access modifiers of C++ allows us to determine which class
members are accessible to other classes and functions, and
which are not.
Public Access Modifier in C++
All the variables and functions declared under public access
modifier will be available for everyone. They can be accessed
both inside and outside the class. Dot (.) operator is used in
the program to access public data members directly.
Classes, Object Public and Private access modifiers

Private Access Modifier in C++


All the variables and functions declared under a private
access modifier can only be used inside the class. They are
not permissible to be used by any object or function outside
the class. By default all the data member are classified as
private access modifier.
Protected Access Modifier in C++
Protected access modifier is similar to that of private access
modifiers, the difference is that the class member declared as
Protected are inaccessible outside the class but they can be
accessed by any subclass(derived class) of that class
Classes, Object, Public and Private access modifiers

Object in C++
An Object is an instance of a Class. When a class is defined,
no memory is allocated but when it is instantiated (i.e. an
object is created) memory is allocated. Defining Class and
Declaring Objects. A class is defined in C++ using keyword
class followed by the name of class.
6
Algorithm Of Success
While(noSuccess) {
tryAgain();
If(Dead) {
Break;
}
}

You might also like