C++ Interview Questions and Answers for Experienced - 2

Question: 6

What is namespace?

Namespace allows us to group a set of global classes, objects and/or functions under a name.

To say it somehow, they serve to split the global scope in sub scopes known as namespace.

Question: 7

What is an object?

Object is a software bundle of variables and related methods. Objects have state and behavior.

Question: 8

What is polymorphism?

Poly means many and morph means form. Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.

Question: 9

 What is scope resolution operator?

A scope resolution operator (::), can be used to define the member functions of a class outside the class.

Question: 10

What are virtual functions?

Virtual functions are used with inheritance, they are called according to the type of object pointed or referred, not according to the type of pointer or reference. In other words, virtual functions are resolved late, at runtime. Virtual keyword is used to make a function virtual.

C++ program with runtime polymorphism (use of virtual functions)

A base class and a derived class.

A function with same name in base class and derived class.

A pointer or reference of base class type pointing or referring to an object of derived class.

Related Questions