Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which among the following is the most abstract form of class?(a) Cars(b) BMW cars(c) Big cars(d) Small carsI had been asked this question in an interview.My question is based upon Class Use topic in division Classes of Object Oriented Programming

Answer» CORRECT option is (a) Cars

The explanation: The most abstract class is class Cars. The class Cars is the most general FORM of all other cars. If it is a BRAND of car, it comes under car. If it is the TYPE of car then ALSO it comes under Cars.
2.

Why do classes use mutator methods?(a) Allows client to modify the program(b) Allows client to modify/write the private members(c) Allows servers to access all the private data(d) Allows servers to access only protected membersThis question was posed to me during an interview.My question is from Class Use in division Classes of Object Oriented Programming

Answer»

Correct OPTION is (b) Allows CLIENT to modify/write the private members

The best EXPLANATION: The client can have rights to access a file and write something to it. This is mandatory to keep the private data updated. Also it is an ADVANTAGE over the use of hidden CLASS members.

3.

Why do classes use accessor methods?(a) To make public data accessible to client(b) To make public data private to client(c) To make private data public for whole program(d) To make private data accessible to the clientI have been asked this question during an online interview.Enquiry is from Class Use topic in division Classes of Object Oriented Programming

Answer»

Correct answer is (d) To make private data accessible to the client

Explanation: The private data of a class is usually not accessible. But the data can be accessed by the USER using ACCESSOR FUNCTIONS. These functions ALLOWS the user to get the data stored as private in a class.

4.

Why do we use user defined classes?(a) To design a user intended code(b) To model real world objects(c) To design the interfaces(d) To model the functionsI have been asked this question in examination.Query is from Class Use topic in chapter Classes of Object Oriented Programming

Answer»

Correct choice is (B) To model real world objects

The best EXPLANATION: The primitive classes are not sufficient for the programming complex algorithms. Some USER defined classes are required to represent a real world object and to DEFINE a blueprint of what the class should actually contain. The user defined classes are as per the requirements and NEED of user.

5.

Which feature is exhibited by the inbuilt classes?(a) Code reusability(b) Code efficiency(c) Code readability(d) Code reusability, efficiency and readabilityI have been asked this question during a job interview.My enquiry is from Class Use in portion Classes of Object Oriented Programming

Answer»

Correct OPTION is (d) Code reusability, efficiency and readability

To EXPLAIN I would say: The code is reusable as the FUNCTIONS which are already WRITTEN, can be used anytime required. The code becomes easier to read. Also, the code is efficient as there is no need to assign any external code.

6.

What is the use of inbuilt classes?(a) Provide predefined data(b) Provide predefined functions(c) Provide predefined data and functions(d) Provide predeclared data to be overriddenThe question was asked during an interview.Query is from Class Use topic in division Classes of Object Oriented Programming

Answer»

Right choice is (c) PROVIDE predefined data and FUNCTIONS

Best explanation: The data that is constant or is always the same initially for use can be PROVIDED by some inbuilt classes. The functions that are mostly USED are also provided by the inbuilt classes. The data and functions can be used by INCLUDING the corresponding header file or library.

7.

In which case the classes can be used to make the more efficient program?(a) To define a function that is called frequently in a program(b) To structure data that is most similar(c) To group the most similar data and operations(d) To define a blueprint that shows memory location of dataThis question was addressed to me in an online interview.The query is from Class Use topic in division Classes of Object Oriented Programming

Answer»

Right OPTION is (c) To group the most similar data and OPERATIONS

The explanation: The classes would be more suitable to use in case where we need to group the most similar data and operations. The data can be REPRESENTED as data members of class and operations as member functions of class. This is indirectly ENCAPSULATION feature.

8.

Class is _____________ of an object.(a) Basic function definition(b) Detailed description with values(c) Blueprint(d) Set of constant valuesThis question was posed to me in an online quiz.I'm obligated to ask this question of Class Use topic in section Classes of Object Oriented Programming

Answer»

The correct choice is (c) Blueprint

To explain: The class is an OVERVIEW for an OBJECT. It contains the basic details MAP of data that an object will contain. An object is INDEPENDENT representation of class.

9.

Which among the following is a feature of class?(a) Object orientation(b) Procedure orientation(c) Both object and procedure orientation(d) Neither object nor procedure orientationI have been asked this question in semester exam.I need to ask this question from Class Use topic in section Classes of Object Oriented Programming

Answer»

Right choice is (a) OBJECT orientation

The best explanation: Thee use of classes feature the object oriented programming. The OOP CONCEPT can be IMPLEMENTED by using class and their OBJECTS. Procedures orientation is not a feature of OOP.

10.

Which among the following is an advantage of using classes over structures of C?(a) Functions are restricted(b) Functions can’t be defined(c) Functions can also be encapsulated(d) Functions can have more securityThe question was posed to me in an interview for internship.My question is taken from Class Use in chapter Classes of Object Oriented Programming

Answer»

The correct option is (c) Functions can also be encapsulated

The BEST explanation: The functions are also made easy to be encapsulated INSIDE a class. In structures, only the data members were allowed to be encapsulated. HENCE classes can represent an entity in a better WAY.

11.

Which class represents the most abstracted information?(a) Nested(b) Derived(c) Enclosed(d) BaseI have been asked this question by my school teacher while I was bunking the class.My question is based upon Class Use topic in division Classes of Object Oriented Programming

Answer»

The CORRECT CHOICE is (d) Base

Best explanation: The base CLASSES are the most abstracted part of INFORMATION. A base class having many other derived classes would have a bigger overview of all the other derived classes. Hence the base classes have the most abstract information.

12.

If a database have to be maintained using OOP, to store the details of each employee in a company, which would be the best choice among the following?(a) Define a class to store details of each employee(b) Define a structure to store details of each employee(c) Define separate variable for each detail(d) Define a generic type to store string and number detailsI have been asked this question in class test.The above asked question is from Class Use in chapter Classes of Object Oriented Programming

Answer»

Right choice is (a) Define a class to store details of each employee

Easy explanation - A single class can be defined that REPRESENTS a single employee of a company. The SPECIFIC type of FUNCTIONS that can be applied to specific employees can be put into ANOTHER class that is derived from the EXISTING class.

13.

If a class have two data members and two functions to add those two numbers and to subtract them, which among the following is most efficient if the programmer wants to implement multiplication too?(a) Define a public function which multiplies two numbers(b) Define a public function that returns values of two data members(c) Define a private function which multiplies two numbers(d) Define a private function that returns values of two data membersI have been asked this question in a national level competition.The question is from Class Use in section Classes of Object Oriented Programming

Answer»

The correct option is (b) Define a public function that RETURNS values of two data MEMBERS

Easy explanation - The best choice would be to define a public member function that returns the values of two data members of the class. This WAY we can implement any operation on those data members. Also there won’t be any need to MODIFY the program and to add NEW functions for each new operation.

14.

To group all the brands of cars, what should be used?(a) Class(b) Structure(c) Function(d) ObjectThis question was addressed to me in an interview.Question is taken from Class Use in chapter Classes of Object Oriented Programming

Answer»

The CORRECT choice is (a) Class

Easy explanation - A class can be used to GROUP all the BRANDS of cars. The Different brands may have different properties but all will have some common properties like number of wheels and doors, accessories etc. All of those properties can be grouped into a SINGLE class REPRESENTING all the cars.

15.

Which among the following is the main characteristic of class?(a) Inheritance(b) Encapsulation(c) Polymorphism(d) Object creationThe question was posed to me in a national level competition.My question is taken from Class Use topic in chapter Classes of Object Oriented Programming

Answer»

Correct choice is (b) Encapsulation

For explanation: The classes are MADE to encapsulate the DATA and properties that are most similar and can be grouped TOGETHER inside a SINGLE class. This single class can represent all of those features by creating its instances.

16.

Deriving a class in such a way that that the base class members are not available for further inheritance is known as ___________________(a) Public inheritance(b) Protected inheritance(c) Protected or private inheritance(d) Private inheritanceI got this question in an online quiz.My doubt stems from Derived Class in portion Classes of Object Oriented Programming

Answer»

The correct option is (d) PRIVATE INHERITANCE

Explanation: The private members of a class can NEVER be derived to another class. When a class derives another class using private inheritance, all the members become private members of the derived class. Hence these member won’t be AVAILABLE for further inheritance.

17.

Which feature is not related to the derived classes among the following?(a) Inheritance(b) Encapsulation(c) Run time memory management(d) Compile time function referencesThe question was asked by my college director while I was bunking the class.I need to ask this question from Derived Class topic in chapter Classes of Object Oriented Programming

Answer» CORRECT option is (c) Run TIME memory MANAGEMENT

Easy EXPLANATION - The memory management is the feature that is not necessary for DERIVED classes that will be a part of whole program. The functions references must be resolved for their proper use if inheritance is used.
18.

The members of a derived class can never be derived.(a) True(b) FalseThis question was posed to me in an interview for internship.My enquiry is from Derived Class topic in section Classes of Object Oriented Programming

Answer» RIGHT option is (b) False

Easiest explanation - This is not true that the members of a derived class can’t be derived. All the classes are considered to be a normal class when used for derivation. The members can be derived with RESPECT to their ACCESS SPECIFIERS.
19.

How many classes can be derived from a derived class?(a) Only 1(b) At most 1(c) At least 1(d) As many as requiredThis question was posed to me in unit test.This interesting question is from Derived Class in chapter Classes of Object Oriented Programming

Answer»

Correct option is (d) As many as required

The EXPLANATION: When a CLASS is to be derived from another derived class, the derived class behaves as a normal base class hence there are no RESTRICTION on how many class can be derived from a derived class. The derived class again behaves as a normal SUPERCLASS.

20.

If base class is an abstract class then derived class ______________ the undefined functions.(a) Must define(b) Must become another abstract class or define(c) Must become parent class for(d) Must implement 2 definitions ofI have been asked this question during an interview.This intriguing question originated from Derived Class in portion Classes of Object Oriented Programming

Answer»

Correct choice is (B) Must become another ABSTRACT CLASS or define

The explanation: The function must be defined in the PROGRAM which are not defined in the base class. Hence the class must be defined as abstract of implement the function DEFINITION in it.

21.

If class A is derived from another derived class B which is derived from class C, which class will have maximum level of abstraction?(a) Class A(b) Class B(c) Class C(d) All have the same level of abstractionThe question was asked during an interview.Origin of the question is Derived Class topic in portion Classes of Object Oriented Programming

Answer»

Right answer is (c) CLASS C

The best EXPLANATION: The ABSTRACTION level of class C will be maximum. This is because the parent class have higher level of abstraction. Hence the parent of all other class will have maximum level of abstraction.

22.

Derived class is also known as ______________ class.(a) Subclass(b) Small class(c) Big class(d) Noticeable classI have been asked this question in an online interview.My question is based upon Derived Class topic in chapter Classes of Object Oriented Programming

Answer» CORRECT answer is (a) Subclass

Easiest explanation - It is just another NAME given to the derived CLASSES. This is used while denoting all the derived classes subsequent to a superclass.
23.

If a class is being derived using more than two base classes, which inheritance will be used?(a) Single(b) Multi-level(c) Hierarchical(d) MultipleI had been asked this question in homework.Question is from Derived Class in chapter Classes of Object Oriented Programming

Answer» CORRECT option is (d) Multiple

To explain: The statement given is the definition of multiple INHERITANCE with respect to the derived class. The concept can be ILLUSTRATED with many other samples but the main ASPECTS are base class and derived class only.
24.

Which among the following is correct?(a) Friend function of derived class can access non-private members of base class(b) Friend function of base class can access derived class members(c) Friend function of derived class can access members of only derived class(d) Friend function can access private members of base class of a derived classThe question was asked in a national level competition.Origin of the question is Derived Class topic in portion Classes of Object Oriented Programming

Answer»

The correct option is (a) Friend function of derived class can access non-private members of base class

To EXPLAIN I would say: The friend function of a class can access the non-private members of base class. The reason behind is that the members of base class GETS derived into the derived class and hence BECOME members of derived class too. Hence a friend function can access all of those.

25.

How many derived class can a single base class have?(a) 1(b) 2(c) 3(d) As many are requiredI had been asked this question in semester exam.My question is from Derived Class topic in portion Classes of Object Oriented Programming

Answer»

The correct option is (d) As many are required

Best EXPLANATION: There is no RESTRICTION on how many classes can INHERIT a SINGLE base class. Hence there can be as many DERIVED classes as required in a program from a single base class.

26.

How many types of inheritance are supported in C++ for deriving a class?(a) 1(b) 2(c) 3(d) 4The question was asked in a national level competition.The doubt is from Derived Class in chapter Classes of Object Oriented Programming

Answer»

The correct choice is (c) 3

Best EXPLANATION: There are three types of inheritance possible. PRIVATE inheritance, protected inheritance, and public inheritance. The inheritance defines the ACCESS specifier to be used with the INHERITED members in the derived CLASS.

27.

Which members can never be accessed in derived class from the base class?(a) Private(b) Protected(c) Public(d) All except privateI have been asked this question in semester exam.This interesting question is from Derived Class in chapter Classes of Object Oriented Programming

Answer»

Right choice is (d) All except PRIVATE

To explain I would SAY: There is no restriction for a DERIVED CLASS to access the members of the base class until and unless the members are private. Private member are declared so that those members are not accessible OUTSIDE the class.

28.

If there is a derived class in a program, how many classes must be in that program?(a) 1(b) 2(c) 3(d) 4I have been asked this question by my school teacher while I was bunking the class.The doubt is from Derived Class in portion Classes of Object Oriented Programming

Answer»

Right CHOICE is (b) 2

The EXPLANATION is: If there is a DERIVED class in a program, there must be at least 2 CLASSES in that program. One is a base class and ANOTHER derived class. Hence at least 2 classes must be there.

29.

Which among the following is inherited by a derived class from base class?(a) Data members only(b) Member functions only(c) All the members except private members(d) All the members of base classI have been asked this question during an online interview.Enquiry is from Derived Class in portion Classes of Object Oriented Programming

Answer»

Correct choice is (C) All the members except private members

To explain: The class inheriting another class, inherits all the data members and MEMBER functions that are not private. This is done to ENSURE the SECURITY features with maximum FLEXIBILITY.

30.

Which among the following is best definition of a derived class?(a) A child class(b) A class which inherits one or more classes(c) A class with keyword derived(d) A class with more than one constructorI have been asked this question in semester exam.Enquiry is from Derived Class topic in chapter Classes of Object Oriented Programming

Answer»

Correct answer is (B) A CLASS which INHERITS one or more classes

The best I can explain: Any class which inherits one or more classes is a DERIVED class. The only condition is it MUST inherit at least one class in order to be called as a derived class.

31.

If a base class is added with a few new members, its subclass must also be modified.(a) True(b) FalseI have been asked this question during an online exam.My question is based upon Base Class in section Classes of Object Oriented Programming

Answer»

The correct CHOICE is (b) False

Explanation: The base class can be ADDED with new members WITHOUT AFFECTING the subclasses. This is because the subclasses may GET some more features inherited but it won’t use them. But the base class will be able to use the new members as would be required.

32.

How many base classes can a single derived class have in C++?(a) 1(b) 2(c) 3(d) As many as requiredI had been asked this question in an international level competition.The above asked question is from Base Class in division Classes of Object Oriented Programming

Answer»

Correct option is (d) As many as required

To explain I WOULD say: This is because C++ allows multiple INHERITANCE. A DERIVED CLASS can have more than ONE base class and hence can derive all of their features.

33.

If a base class is inherited from another class and then one class derives it, which inheritance is shown?(a) Multiple(b) Single(c) Hierarchical(d) Multi-levelI have been asked this question by my college professor while I was bunking the class.Origin of the question is Base Class in chapter Classes of Object Oriented Programming

Answer»

The correct CHOICE is (d) Multi-level

The best explanation: If a base class is inherited from another class, SINGLE inheritance is SHOWN. But when ONE more class inherits the derived class, this becomes a multi-level inheritance.

34.

Can we call methods of base class using the constructor of the derived class?(a) Yes, always(b) Yes, but not always(c) No, never(d) No, but we can call in some casesI had been asked this question during an internship interview.My doubt stems from Base Class in chapter Classes of Object Oriented Programming

Answer»

The correct option is (a) Yes, always

Explanation: If the FUNCTION is defined in the base class, it can always be called from the CONSTRUCTOR of its derived class. Since the CONSTRUCTORS are not PRIVATE, they can be accessed in derived class even if those are PROTECTED.

35.

Always the base class constructors are called ___________ constructor of derived class.(a) Before(b) After(c) Along(d) According to priority ofI had been asked this question in an interview for internship.The doubt is from Base Class topic in portion Classes of Object Oriented Programming

Answer»

Correct choice is (a) Before

The best I can explain: When the BASE class object is CREATED, its constructor will be called for sure. But if a derived class constructor is called, FIRST base class constructor is called and then derived class constructor is TAKEN into consideration.

36.

Base class have ________________ of abstraction.(a) Higher degree(b) Lower degree(c) Intermediate(d) Minimum degreeI had been asked this question in an international level competition.I'm obligated to ask this question of Base Class in portion Classes of Object Oriented Programming

Answer» CORRECT choice is (b) LOWER degree

The EXPLANATION is: A base class will have LESSER information as compared to those of derived classes. Since derived classes inherit the base class properties and then add on their own features, they elaborate more hence have lower degree of abstraction.
37.

If a class is enclosing more than one class, than it can be called as base class of those classes.(a) True(b) FalseThis question was addressed to me in quiz.My enquiry is from Base Class topic in portion Classes of Object Oriented Programming

Answer»

Right OPTION is (B) False

Explanation: When a class have more than one nested classes, it is known as enclosing class. It can’t be called as parent or BASE class SINCE there is no inheritance INVOLVED.

38.

Which type of members can’t be accessed in derived classes of a base class?(a) Protected(b) Private(c) Public(d) All can be accessedI had been asked this question at a job interview.I'd like to ask this question from Base Class in section Classes of Object Oriented Programming

Answer»

Right answer is (B) Private

The explanation: The private members can be accessed only INSIDE the base CLASS. If the class is derived by other classes. Those members will not be ACCESSIBLE. This concept of OOP is made to make the members more secure.

39.

Which among the following must be in a base class?(a) Data members(b) Member functions(c) Access specifiers(d) NothingI got this question during an internship interview.Asked question is from Base Class in chapter Classes of Object Oriented Programming

Answer»

Right ANSWER is (d) Nothing

Easy EXPLANATION - EVEN a class that doesn’t have any members can be a BASE class. It is not mandatory to have any member or ATTRIBUTE in base class.

40.

If a base class is being derived by two other classes, which inheritance will that be called?(a) Single(b) Multiple(c) Multi-level(d) HierarchicalI had been asked this question during an online exam.I would like to ask this question from Base Class topic in section Classes of Object Oriented Programming

Answer»

The correct answer is (d) Hierarchical

For explanation: When more than one classes are being DERIVED from a single PARENT class, the INHERITANCE is KNOWN as hierarchical inheritance. This is usually USEFUL when the base class is higher abstraction of its derived classes.

41.

How to make a derived class a base class?(a) Change name of the class(b) Use keyword base(c) Make a class derive from it(d) Can’t be doneThe question was asked in exam.The origin of the question is Base Class topic in division Classes of Object Oriented Programming

Answer»

Right option is (c) Make a class DERIVE from it

Easy explanation - MAKING another class derive from it will make that class as base class. It is not necessary that we have to write DIFFERENT code for it. If at least one class DERIVES that class, it becomes the base class for the new class.

42.

How many base classes can a single class inherit in java?(a) 1(b) 2(c) 3(d) As many as requiredThis question was addressed to me during an online exam.The origin of the question is Base Class in division Classes of Object Oriented Programming

Answer»

Right option is (a) 1

Explanation: In java, multiple inheritance is not SUPPORTED, which LEADS to the FACT that a class can have only 1 parent class if inheritance is used. Only if interfaces are used then the class can implement more than one base class.

43.

An abstract class is always a __________ class.(a) Base(b) Derived(c) Template(d) NestedI got this question during an interview.I'd like to ask this question from Base Class topic in chapter Classes of Object Oriented Programming

Answer»

Right choice is (a) Base

To explain I would say: Every ABSTRACT CLASS is a base class. It must be so, because the FUNCTIONS which are not defined INSIDE the abstract class, must be defined in the derived classes. HENCE it becomes a base class.

44.

A base class is also known as _____________ class.(a) Basic(b) Inherited(c) Super(d) SubThis question was addressed to me by my college professor while I was bunking the class.My question is from Base Class in section Classes of Object Oriented Programming

Answer»

Right option is (C) Super

Explanation: A class which is being DERIVED by other classes, is CALLED as super class. This concept is clearly USED in java as we call the functions of a base class by using the keyword super as required.

45.

Which is most appropriate definition of a base class?(a) It is parent of any of its derived class(b) It is child of one of the parent class(c) It is most basic class of whole program(d) It is class with maximum number of membersI got this question in an international level competition.I need to ask this question from Base Class in section Classes of Object Oriented Programming

Answer» CORRECT ANSWER is (a) It is PARENT of any of its derived class

The explanation: A class which is parent of another class, or from which other classes can be derived, is known as a base class. It is mandatory that a class MUST have at least ONE derived class to be called as a base class.
46.

Template classes must have at least one static member.(a) True(b) FalseThe question was posed to me during an internship interview.My question is based upon Template Class in division Classes of Object Oriented Programming

Answer»

Right option is (b) False

To explain I would say: There is no mandatory CONDITION to have static members INSIDE TEMPLATE CLASS. Not only template, it is not mandatory to have static members ANYWHERE. We can use them as required in the code.

47.

How many generic types can be given inside a single template class?(a) Only 1(b) Only 3(c) Only 7(d) As many as requiredThe question was posed to me during an online exam.My enquiry is from Template Class topic in section Classes of Object Oriented Programming

Answer»

Right OPTION is (d) As MANY as required

Best explanation: There is no restriction on the number of types to be USED for making the class GENERIC. There can be any number of generic types with a single class. Hence giving flexibility to code with all the data types.

48.

What are the two specializations of I/O template classes in C++?(a) 16-bit character and wide characters(b) 8-bit character and wide characters(c) 32-bit character and locale characters(d) 64-bit characters and locale charactersI had been asked this question in unit test.My doubt stems from Template Class topic in division Classes of Object Oriented Programming

Answer»

Correct CHOICE is (b) 8-bit CHARACTER and wide characters

The best explanation: The I/O specialization is made with wide character and 8-bit characters. Wide characters are used to STORE the characters that might take more than 1 byte of space in memory or any SIZE that is DIFFERENT from the one that the machine is using.

49.

A template class defines the form of a class _____________________ it will operate.(a) With full specification of the data on which(b) With full specification of the functions on which(c) Without full specification of the data on which(d) Without full specification of the functions on whichI had been asked this question in an internship interview.Question is taken from Template Class topic in portion Classes of Object Oriented Programming

Answer»

Right ANSWER is (c) WITHOUT full specification of the data on which

The BEST I can explain: The template classes can ACCEPT all types of data types. There is no need to specify the data on which the class has to operate. Hence it gives US flexibility to code without worrying about the type of data that might be used in the code.

50.

Which is the most significant feature that arises by using template classes?(a) Code readability(b) Ease in coding(c) Code reusability(d) Modularity in codeI had been asked this question in an online quiz.The above asked question is from Template Class in section Classes of Object Oriented Programming

Answer»

Correct choice is (c) Code REUSABILITY

Explanation: The code reusability is the feature that becomes more powerful with the USE of template CLASSES. You can generate a single code that can be used in variety of PROGRAMMING SITUATIONS.