C++ Interview Questions and Answers for Freshers - 1

Question: 1

What is Polymorphism?

Polymorphism means that some code or operations or objects behave differently in different contexts.

In C++, following features support polymorphism.

Compile Time Polymorphism: means compiler knows which function should be called when a polymorphic call is made. C++ supports compiler time polymorphism by supporting features like templates, function overloading and default arguments.

Run Time Polymorphism: is supported by virtual functions. The idea is virtual functions 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.

Question: 2

What is encapsulation?

Encapsulation is referred to one of the following two notions.

Data hiding: A language feature to restrict access to members of an object. For example, private and protected members in C++

Bundling of data and methods together: Data and methods that operate on that data are bundled together.

Question: 3

What is a 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 specifies of the working of a class.

Question: 4

What is the difference between an object and a class?

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

A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don’t change.

The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.

An object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that life lifetime, the attributes of the objects may undergo significant change.

Question: 5

What is abstraction?

Abstraction is of the process of hiding unwanted details from the user.

Related Questions