OOPs Interview Questions with Answers for Freshers

OOPs Interview Questions with Answers for Freshers

No matter whether you are a JAVA or C# or C++ professional. Object Oriented Programming (OOPs) Technique is common to all high level languages. I experienced during a Technical interview nearly all experienced interviewers prefer to ask OOPs related interview questions. Compare to an experienced professional a fresher can have more chance to face OOPs interview questions during his/her Career journey. Object Oriented Programming technique is not at all difficult to learn but it is little bit confusing. That’s why to judge a fresher interviewers use OOPs interview questions. To make your Career journey easier here in this session we are sharing the most frequently asked OOPs interview questions with answers. Read thoroughly the below interview questions before visit the interviewer.

What is an Object?

Objects are the physical and conceptual things that found in the universe. Hardware, Software, documents, human being and even concepts are all examples of objects.

What is a Class?

The object with the same data structure (attributes) and behaviors (operations) are grouped into a single entity is called class.

What is Polymorphism?

Polymorphism refer to the ability of an object to have numerous methods with the same name. This is also referred to as function overloading. An object can have multiple functions with the same name but different parameter lists. The appropriate function to execute is chosen depending on which parameter list is provided in the function call.

What do you mean by inheritance in OOPs?

Inheritance is a process by which one object can acquire the characteristics from one or more other objects. Here the best example is the generation. Watch your-self you must inherited many properties from your parents and grand parents.

What is a Constructor?

A Constructor function is a special function that is a member of a class and has the same name as that of class. A Constructor is the first member function executed automatically when the object is created. Constructor should be declared in the public section of the class. Constructor should not have any return values. They have no return type specified. Constructor can have arguments. So they can be overloaded.

What is Copy Constructor?

The initialization of one class object with another object of its class is referred to as default member-wise initialization. Conceptually, the copying of one class object with another is accomplished by copying each of the non-static class data members. The class designer can override the default behavior by providing a special class copy constructor. It is invoked whenever one class object is initialized with another object of its class. Defining a copy constructor help to prevent problems that might occur when one object is used to initialize another.

What is a Destructor?

When a object is no longer needed, it can be destroyed. A destructor is a special user-defined member function that is invoked automatically whenever an object of its class goes out of scope or whenever the delete expression is applied to a pointer to a class object. This function complements the operation performed by any of the constructors. The destructor is given the name of the class prefixed with a tilde (~). It can neither return a value nor can it take any parameters. Because it can’t specify any parameters, it can’t be overloaded.

What is the difference between Early & Late Binding?

The function overloading is a polymorphic behavior where there is one name for the function, but multiple forms. The multiple forms arise out of varying signatures and argument types received by the functions. When one overloaded function is called, the compiler matches the arguments passed with the signature of various functions with same name. Once the match is found, the appropriate function is linked at the compiler time itself. This is called early binding or static binding.

When the function in the same name and signature are defined in both base class as well as derived class, the concept of the virtual function will be implemented. In these type of cases, the functions in base class and derived class are invoked with the help of the base class pointer. Hence the compiler delays the linking of the function to refer to till run-time. Although the function is called through the base class pointer, the actual function invoked will be determined at run-time. Since the function to be executed is determined only at run-time is called late binding or dynamic binding.

Why you required Virtual Function?

In C++, a function call can be bound to the actual function either at compile time or at run-time. Resolving a function call at compile time is known as compile-time or early or static binding, whereas resolving a function call at run-time in known as run-time or late or dynamic binding. Run-time polymorphism allows postponing the decision of selecting the suitable member functions until run-time. In C++, this is achieved by using Virtual functions.

What do you mean by Abstract Class?

A class containing pure Virtual functions can’t be used to define any objects of its own. Such classes are called abstract classes. Abstract classes can be used as a framework upon which new classes can be built to provide a new functionality.

What is Friend Functions?

There are 3 levels of internal protection for the different members of a class: public, protected and private. The protected and private members can’t be accessed from outside the same class at which they are declared. It is possible to grant a non-member function access to the private members of a class by using a keyword friend. A friend function has access to all private and protected members of the class for which it is a friend. Special characters of a friend functions are it is not a member function of the class. It is like a normal external functions. It is not in the scope of the class to which it has been declared. It can be declared either public or private section of the class.

Book: Object Oriented Programing using C++
Author: Alok Kumar Jagadev, Amiya Kumar Rath, Satchidananda Dehuri

Source of image: https://fthmb.tqn.com