Turn Desktop View Off
by Dinesh Thakur

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

Virtual functions play an important role in object oriented programming. Ordinary functions use the concept of early binding. However virtual functions help in late binding. The concept of pointers playa vital role in Virtual functions.

 
by Dinesh Thakur

Destructors are used for reinitializing the objects which are initialized by the constructors. With the help of destructors, the objects are destroyed. This special member function is called automatically when an object is destroyed. A Destructor function also has the same name as that of the class but it is preceded by a ~, symbol.

 
by Dinesh Thakur

The member functions are created and placed in the memory space only once when they are defined as a part of a class specification. Since· all the objects belonging to that class use the same member functions, no separate space is allocated for member functions when the objects are created. For each object, memory is allocated only for member data. Separate memory locations for the objects are essential since the member variables hold different data values for different objects.



 
by Dinesh Thakur

Member of a class can be accessed only through the object of a class. The members are accessed as follows:

 
by Dinesh Thakur

The difference between a structure and a class is that, in a class, the member data or functions are private by default whereas, in a structure, they are public by default. The following segment

 
by Dinesh Thakur

The const qualifier is used with the variables of basic data types to prevent them from being modified by the function. In a similar way, const qualifier can also be applied to member functions, member function arguments and the objects of a class.



 
by Dinesh Thakur

A function can also return objects either by value or by reference. When an object is returned by value from a function, a temporary object is created within the function, which holds the return value. This value is further assigned to another object in the calling function.

 
by Dinesh Thakur

The objects of a class can be passed as arguments to member functions as well as nonmember functions either by value or by reference. When an object is passed by value, a copy of the actual object is created inside the function. This copy is destroyed when the function terminates. Moreover, any changes made to the copy of the object inside the function are not reflected in the actual object. On the other hand, in pass by reference, only a reference to that object (not the entire object) is passed to the function. Thus, the changes made to the object within the function are also reflected in the actual object.

 
by Dinesh Thakur

Like array of other user-defined data types, an array of type class can also be created. The array of type class contains the objects of the class as its individual elements. Thus, an array of a class type is also known as an array of objects. An array of objects is declared in the same way as an array of any built-in data type.



 
by Dinesh Thakur

Arrays can be declared as the members of a class. The arrays can be declared as private, public or protected members of the class.

 
by Dinesh Thakur

The members of a class can be directly accessed inside the class using their names. However, accessing a member outside the class depends on its access specifier. The access specifier not only determines the part of the program where the member is accessible, but also how it is accessible in the program.

 
by Dinesh Thakur

Once a class is defined, it can be used to create variables of its type known as objects. The relation between an object and a class is the same as that of a variable and its data type.



 
by Dinesh Thakur

Member functions of a class can be defined either outside the class definition or inside the class definition. In both the cases, the function body remains the same, however, the function header is different.

 
by Dinesh Thakur

A class is a user-defined data type that binds data and the functions that operate on the data together in a single unit. Like other user-defined data types, it also needs to be defined before using its objects in the program. A class definition specifies a new data type that can be treated as a built-in data type.



 
by Dinesh Thakur

Polymorphism (a Greek word meaning having multiple forms) is the ability of an entity such as a function or a message to be processed in more than one form. It can also be defined as the property of an object belonging to a same or different class to respond to the same message or function in a different way. For example, if a message change_gear is passed to all the vehicles then the automobiles will respond to the message appropriately however, the pulled vehicles will not respond. The concept of polymorphism plays an important role in OOP as it allows an entity to be represented in various forms.

 
by Dinesh Thakur

Abstraction is a mechanism to' hide irrelevant details and represent only the essential features so that one can focus on important things at a time; It allows managing complex systems by concentrating on the essential features only. For example, while driving a car, a driver only knows the essential features to drive a car such as how to use clutch, brake, accelerator, gears, steering, etc., and least bothers about the internal details of the car like motor, engine, wiring, etc.

 
by Dinesh Thakur

A feature of some programming languages in which the same 0PERATORmay be used on different data types with different, but analogous, results. For example most languages permit the same operator + to add either INTEGER or FLOATING-POINT numbers, and many further allow it to be used to CONCATENATE strings, so that 'rag' + 'mop' produces 'ragmop'. A few languages, including C++, allow the programmer to create new operator overloading.



 
by Dinesh Thakur

#include <iostream.h>

#include<conio.h>

 
by Dinesh Thakur

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

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

Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.

 
by Dinesh Thakur

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

1: constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.

 
by Dinesh Thakur

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.

 
by Dinesh Thakur

Overloading: When a single Object has multiple behaviors. Then it is called as Overloading. Overloading is that in which a Single Object has a same name and Provides Many Functions. In Overloading followings things denotes Overloading:-

 
by Dinesh Thakur

Early Binding:Early Binding Always Occur in the Polymorphism, when we pass the Reference of a sub Class into the Pointer Object of Base Class, then the Member Functions Are never to be Override. When we execute the Program then Compiler knows this thing. This is called as Early Binding. And the Compiler will Execute the Member Functions of Base Class and this will never overrides the Body of the Sub Class Member Function. This is known as the early binding.

 
by Dinesh Thakur

In the Inheritance when we Points or Pass the Reference of Second Class Object into the Pointer Object of First Class , then the Pointer object of first class will call only the Constructor of Sub Class But Destructors are not Called With the help of Base Class Pointer Object. Because the Statements or Destructors of Base Class are never Override.

 
by Dinesh Thakur

In the Hierarchical Inheritance, when we use The Same Data Member in the Sub Class Then the Data Member will Contains the Many values So that here Data Member will be Ambiguous Because a Single Data Member have two or more values.

 
by Dinesh Thakur

We know that C++ is an OOP language that is code of C++ may Contains classes there is a main Method which also Reside in Class.

 
by Dinesh Thakur

Storage Classes are used to determine in which space the value of variable will Stored. And what will be the value of variable, when we doesn’t Specify the value of variable. And In what Place we can use the value of variable. The Storage Classes Determines the Following things.

 

Page 1 of 2