by Dinesh Thakur Category: Classes in C++

1: Public, protected and private are three access specifier in C++. Public data members and member functions are accessible outside the class. Protected data members and member functions are only available to derived classes. Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes. Write a function that swaps the values of two integers, using int* as the argument type.

 
by Dinesh Thakur Category: Classes in C++

Class : Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class. Class is a successor of Structure. By default all the members inside the class are private.



 
by Dinesh Thakur Category: Classes in C++

Encapsulation is the technique of binding or keeping together the data and the functions (that operate on them) in a single unit called a class. Encapsulation is the way to implement data abstraction. A well-encapsulated object acts as a 'black box' for other parts of the program. That is, it provides services to the external functions or other objects that interact with it. However, these external functions or the objects do not need to know its internal details. For example, the data p_code, p_name, p_price and qty_in_hand and the functions display-product() and check_qty are encapsulated in a class Product.

 
by Dinesh Thakur Category: Classes in C++

Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

 
by Dinesh Thakur Category: Classes in C++

A virtual function is a function that is declared as virtual in a base class. A virtual function is always preceded by the keyword virtual. Virtual functions employ late binding by allocating memory space during execution time and not during compilation time. In this case when a pointer of the base class is defined in a main() function and derived class object's address is passed on to the base class pointer, then calling the overridden function will invoke the derived class member function and not the base class member function as mentioned earlier. Following is a program to illustrate the use of virtual functions.

 
by Dinesh Thakur Category: Classes in C++

Objects are the small, self-contained and modular units with a well-defined boundary. An Object is a Real Word Thing Which performs a Specific Task. An object consists of a state (Properties) and behavior (Method). The state of an object is one of the possible conditions that an object can exist in and is represented by its characteristics or attributes or data or Properties of Object. The behavior of an object determines how an object acts or behaves and is represented by the operations that it can perform. In OOP, the attributes of an object are represented by the variables and the operations are represented by the functions.

 

Page 2 of 6



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles