Explore topic-wise InterviewSolutions in Current Affairs.

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

1.

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 code

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.
2.

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 which

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.
3.

What is the syntax to use explicit class specialization?(a) template class myClass{  }(b) template class myClass{  }(c) template class myClass{  }(d) template class myClass{  }

Answer» Right choice is (d) template <> class myClass{  }

Explanation: The class specialization is creation of explicit specialization of a generic class. We have to use template<> constructor for this to work. It works in the same way as with explicit function specialization.
4.

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 members

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.
5.

Which among the following is the proper syntax for the template class?(a) template ;(b) Template ;(c) template T named(T x, T y){  }(d) Template T1 named(T1 x, T2 y){  }

Answer» Correct option is (c) template T named(T x, T y){  }

Easiest explanation - The syntax must start with keyword template, case sensitive. Then it should include the typename and a variable to denote it. Then whenever that variable is used, it replaces it with the data type needed.
6.

A base class is also known as _____________ class.(a) Basic(b) Inherited(c) Super(d) Sub

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.
7.

If a class is extending/inheriting another abstract class having abstract method, then _______________________(a) Either implementation of method or making class abstract is mandatory(b) Implementation of the method in derived class is mandatory(c) Making the derived class also abstract is mandatory(d) It’s not mandatory to implement the abstract method of parent class

Answer» Correct answer is (a) Either implementation of method or making class abstract is mandatory

Explanation: Either of the two things must be done, either implementation or declaration of class as abstract. This is done to ensure that the method intended to be defined by other classes gets defined at every possible class.
8.

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) Hierarchical

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.
9.

How many base classes can a single class inherit in java?(a) 1(b) 2(c) 3(d) As many as required

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.
10.

Always the base class constructors are called ___________ constructor of derived class.(a) Before(b) After(c) Along(d) According to priority of

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.
11.

Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those member functions as it extends class A. Class C extends class B and implements the other two member functions of class A. Choose the correct option below.(a) Program won’t run as all the methods are not defined by B(b) Program won’t run as C is not inheriting A directly(c) Program won’t run as multiple inheritance is used(d) Program runs correctly

Answer» Correct answer is (d) Program runs correctly

Easiest explanation - The program runs correctly. This is because even class B is abstract so it’s not mandatory to define all the virtual functions. Class C is not abstract but all the virtual functions have been implemented will that class.
12.

Abstract classes can ____________________ instances.(a) Never have(b) Always have(c) Have array of(d) Have pointer of

Answer» The correct choice is (a) Never have

The best I can explain: When an abstract class is defined, it won’t be having the implementation of at least one function. This will restrict the class to have any constructor. When the class doesn’t have constructor, there won’t be any instance of that class.
13.

Use of pointers or reference to an abstract class gives rise to which among the following feature?(a) Static Polymorphism(b) Runtime polymorphism(c) Compile time Polymorphism(d) Polymorphism within methods

Answer» Correct choice is (b) Runtime polymorphism

Easy explanation - The runtime polymorphism is supported by reference and pointer to an abstract class. This relies upon base class pointer and reference to select the proper virtual function.
14.

We ___________________ to an abstract class.(a) Can create pointers(b) Can create references(c) Can create pointers or references(d) Can’t create any reference, pointer or instance

Answer» The correct option is (c) Can create pointers or references

Explanation: Even though there can’t be any instance of abstract class. We can always create pointer or reference to abstract class. The member functions which have some implementation inside abstract itself can be used with these references.
15.

Which among the following is an important use of abstract classes?(a) Header files(b) Class Libraries(c) Class definitions(d) Class inheritance

Answer» Right answer is (b) Class Libraries

To explain I would say: The abstract classes can be used to create a generic, extensible class library that can be used by other programmers. This helps us to get some already implemented codes and functions that might have not been provided by the programming language itself.
16.

How many base classes can a single derived class have in C++?(a) 1(b) 2(c) 3(d) As many as required

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.
17.

How many abstract classes can a single program contain?(a) At most 1(b) At least 1(c) At most 127(d) As many as required

Answer» The correct answer is (d) As many as required

Easiest explanation - There is no restriction on the number of abstract classes that can be defined inside a single program. The programs can use as many abstract classes as required. But the functions with no body must be implemented.
18.

Is it necessary that all the abstract methods must be defined from an abstract class?(a) Yes, depending on code(b) Yes, always(c) No, never(d) No, if function is not used, no definition is required

Answer» The correct answer is (b) Yes, always

Explanation: That is the rule of programming language that each function declared, must have some definition. There can’t be some abstract method that remains undefined. Even if it’s there, it would result in compile time error.
19.

How many types of inheritance are supported in C++ for deriving a class?(a) 1(b) 2(c) 3(d) 4

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.
20.

How many derived class can a single base class have?(a) 1(b) 2(c) 3(d) As many are required

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.
21.

Which members can never be accessed in derived class from the base class?(a) Private(b) Protected(c) Public(d) All except private

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.
22.

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 class

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.
23.

If there is a derived class in a program, how many classes must be in that program?(a) 1(b) 2(c) 3(d) 4

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.
24.

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) Multiple

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.
25.

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 class

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.
26.

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 members

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.
27.

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 references

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.
28.

To group all the brands of cars, what should be used?(a) Class(b) Structure(c) Function(d) Object

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.
29.

Which among the following is the most abstract form of class?(a) Cars(b) BMW cars(c) Big cars(d) Small cars

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.
30.

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 inheritance

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.
31.

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 abstraction

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.
32.

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 required

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.
33.

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 client

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.
34.

Which among the following is false, for a member function of a class?(a) All member functions must be defined(b) Member functions can be defined inside or outside the class body(c) Member functions need not be declared inside the class definition(d) Member functions can be made friend to another class using the friend keyword

Answer» The correct answer is (c) Member functions need not be declared inside the class definition

To explain I would say: Member functions must be declared inside class body, though the definition can be given outside the class body. There is no way to declare the member functions outside the class.
35.

Which of the following is not type of class?(a) Abstract Class(b) Final Class(c) Start Class(d) String Class

Answer» The correct option is (c) Start Class

The best explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable, wrapper, anonymous, input-output, string, system, network. We may further divide the classes into parent class and subclass if inheritance is used.
Previous Next