The colon indicates that the derived-class-name is derived from the base-class-name.

The default visibility mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived.

When a base class is privately inherited by a derived class, 'public members' of the base class become 'private member' of the derived class and therefore the public members of the base class can only be accessed by the member functions of the derived class.

Thus no member of the base class is accessible to the objects of the derived class.

The private member of the base class will never become the member of its derived class.

We can also add our own data and member functions and thus extend the functionality of the base class._________________________________________

Making A Private Member Inheritable:

C++ provides a third visibility modofier protected.

A member declared as protected is accessible by the member functions within its class and any class immediately derived from it. It cannot be accessed by the functions outside these two classes.

When a protected member is inherited in public mode, it become protected in the derived class too.

A protected member, inherited in the private mode, becomes private in the derived class. Although it is available to the member functions of the derived class, it is not available for the further inheritance.

In protected derivation, both the public and protected members of the base class become protected member of the derived class.__________________________________________

An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class.__________________________________________

Constructors in Derived Classes:

As long as no base class constructors takes any arguments ,the derived class need not to have a constructor function.

If any base class constructor contains a constructor with one or more arguments,then it is compulsory for the derived class to have a constructor and pass the arguments to the base class constructor.

When both the derived and base classes contain constructors, the base constructor is executed first and then the constructor in the derived class is executed.

In case of multiple inheritance, the base classes are constructed in the order in which they appear in the declaration of the derived class.
Similarly, in a multilevel inheritance, the constructor will be executed in the order of inheritance.

C++ supports another method of initializing the class objects. This method uses what is known as initialization list in the constructor function.

constructor(arglist):intialization-section
{
assignment-section
}

The assignment-sectionof the constructor function is used to assign initial values to its data members.

Initialization section is used to provide initial values to the base constructors and also to initialize its own class members.
The initialization section basically contains a list of initialization separated by commas.

class demo{
int a;
int b;
public:
demo(int i,int j):a(i),b(2*j){ }
};

main(){
demo x(2,3);// a will be initialize to 2 and b to 6
}

demo(int i,int j):b(i),a(i+j){ } //a will be initialized to 5 and b to 2

The data members are initialized in the order of declaration, independent of the order in the initialization list.

demo(int i,int j):a(i),b(a*j){ } //a is initialized to 2 and b to 6

demo(int i,int j):b(i),a(b*j) //this will nort work since value of b is not available to a which is to be initialized first.__________________________________________

< Happy Coding>

Reference:
OOP by BALAGURUSWAMY

If you want to practice more problem you can visit websites likeGeeksforgeeks
Read articals from it

Popular Posts

Computer programming is one of the fastest growing field. If you are a programmer then you can be hired by a top tech company or you can also work as a freelancer and earn decent amount. So the question arises, how to learn to code ? Initially it was very difficult to learn programming. As there was no internet and you have to relay on books or your colleagues’ code. Now you can find tons of material on the internet. You can learn any computer programming language you want. I am going to tell you some sites which you should visit regularly.

Huffman Code compress data very effectively: saving of 20% to 90% are typical, depending on the characteristics of the data being compressed.Huffman's greedy algorithm uses a table giving how often each character occurs (i.e., its frequency) to build up an optimal way of representing each character as a binary string. This algorithm constructs an optimal prefix code called a Huffman Code.

What is namespace?"In general, a namespace is a container for a set of identifiers Namespaces provide a level of direction to specific identifiers, thus making it possible to distinguish between identifiers with the same exact name. " Or According to Wikipedia “In computer programming namespaces are typically employed for the purpose of grouping symbols and identifiers around a particular functionality and to avoid name collisionsbetween multiple identifiers that share the same name.”