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.

101.

What are static member functions?(a) Functions which use only static data member but can’t be accessed directly(b) Functions which uses static and other data members(c) Functions which can be accessed outside the class with the data members(d) Functions using only static data and can be accessed directly in main() functionThis question was posed to me in examination.This key question is from Types of Member Functions topic in portion Member Functions & its Types of Object Oriented Programming

Answer»

Right CHOICE is (d) Functions using only STATIC data and can be accessed directly in main() function

Explanation: The static MEMBER functions can be accessed directly in the main function. There is no restriction on direct use. We can call them with use of objects also. But the restriction is that the static member functions can only use the static data MEMBERS of the CLASS.

102.

Simple member functions are ______________________(a) Ones defined simply without any type(b) Ones defined with keyword simple(c) Ones that are implicitly provided(d) Ones which are defined in all the classesI got this question in unit test.I would like to ask this question from Types of Member Functions in division Member Functions & its Types of Object Oriented Programming

Answer»

Right option is (a) Ones defined simply without any type

Best explanation: When there is no type defined for any FUNCTION and just a SIMPLE syntax is USED with the return type, function name and parameter LIST then those are known as simple member functions. This is a general DEFINITION of simple members.

103.

How many types of member functions are possible in general?(a) 2(b) 3(c) 4(d) 5The question was asked in an international level competition.My query is from Types of Member Functions in section Member Functions & its Types of Object Oriented Programming

Answer»

Correct choice is (d) 5

The best EXPLANATION: There are basically 5 types of member functions possible. The types include simple, static, const, inline, and FRIEND member functions. Any of these types can be used in a program as per requirements.

104.

The abstract method definition can be made ___________ in derived class.(a) Private(b) Protected(c) Public(d) Private, public, or protectedI have been asked this question during an online interview.My question is based upon Abstract Function topic in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Right answer is (d) Private, public, or protected

Best explanation: The DERIVED class implements the definition of the abstract METHODS of BASE class. Those can be MADE private in derived class if security is NEEDED. There won’t be any problem in declaring it as private.

105.

The abstract methods can never be ___________ in a base class.(a) Private(b) Protected(c) Public(d) DefaultI have been asked this question during an interview.The question is from Abstract Function in division Member Functions & its Types of Object Oriented Programming

Answer»

The CORRECT OPTION is (a) Private

The explanation is: The base class must not contain the abstract methods. The methods have to be derived and defined in derived class. But if it is MADE private it can’t be inherited. HENCE we can’t declare it as a private member.

106.

If a class have all the abstract methods the class will be known as ___________(a) Abstract class(b) Anonymous class(c) Base class(d) Derived classI got this question in final exam.Question is from Abstract Function in division Member Functions & its Types of Object Oriented Programming

Answer» RIGHT answer is (a) Abstract class

Easiest explanation - The CLASSES CONTAINING all the abstract METHODS are known as abstract classes. And the abstract classes can never have any normal function with definition. Hence known as abstract class.
107.

Which among the following is correct for abstract methods?(a) It must have different prototype in the derived class(b) It must have same prototype in both base and derived class(c) It must have different signature in derived class(d) It must have same return type onlyI have been asked this question during an interview.My question comes from Abstract Function topic in section Member Functions & its Types of Object Oriented Programming

Answer»

Right OPTION is (b) It MUST have same prototype in both base and derived class

The EXPLANATION is: The prototype must be the same. This is to override the function declared as abstract in base class. Or ELSE it will not be possible to override the abstract function of base class and hence we GET a compile time error.

108.

Which among the following is true?(a) Abstract methods can be static(b) Abstract methods can be defined in derived class(c) Abstract methods must not be static(d) Abstract methods can be made static in derived classI had been asked this question by my school teacher while I was bunking the class.The doubt is from Abstract Function topic in portion Member Functions & its Types of Object Oriented Programming

Answer»

The correct option is (c) Abstract METHODS must not be static

Explanation: The abstract methods can never be made static. Even if it is in DERIVED class, it can’t be made static. If this happens, then all the subsequent SUB classes will have a common definition of abstract FUNCTION which is not desirable.

109.

Static methods can’t be made abstract in java.(a) True(b) FalseThe question was asked in an internship interview.This key question is from Abstract Function in portion Member Functions & its Types of Object Oriented Programming

Answer»

Correct option is (a) True

Explanation: The abstract functions can’t be made static in a PROGRAM. If those are made static then the function will be a PROPERTY of class RATHER than each object. In TURN ever object or derived class must use the common definition given in the base class. But abstract functions can’t be defined in the base class. Hence not possible.

110.

If a function declared as abstract in base class doesn’t have to be defined in derived class then ______(a) Derived class must define the function anyhow(b) Derived class should be made abstract class(c) Derived class should not derive from that base class(d) Derived class should not use that functionThe question was posed to me during an interview.The question is from Abstract Function in division Member Functions & its Types of Object Oriented Programming

Answer»

The correct choice is (b) Derived CLASS should be made abstract class

To explain: If the FUNCTION that is not to be defined in derived class but is declared as abstract in BASE class then the derived class must be made an abstract class. This will make the concept MANDATORY that the derived class must have one SUBCLASS to define that method.

111.

What is the syntax for using abstract method?(a) abstractmethod_name (parameter)(b) absmethod name (parameter)(c) abstract return-type method name (parameter)(d) abstract method name (parameter)I got this question in semester exam.This intriguing question comes from Abstract Function in section Member Functions & its Types of Object Oriented Programming

Answer»

Right ANSWER is (a) abstractmethod_name (parameter)

The BEST explanation: The syntax must firstly contain the access modifier. Then the keyword abstract is written to mention clearly to the compiler that it is an abstract METHOD. Then PROTOTYPE of the function with return type, function NAME and parameters.

112.

What is this feature of enforcing definitions of abstract function at compile time called?(a) Static polymorphism(b) Polymorphism(c) Dynamic polymorphism(d) Static or dynamic according to needThis question was posed to me in a national level competition.Query is from Abstract Function in division Member Functions & its Types of Object Oriented Programming

Answer» CORRECT choice is (C) Dynamic polymorphism

To EXPLAIN I would say: The FEATURE is known as Dynamic polymorphism. Because the definitions are resolved at RUNTIME. Even though the definitions are checked at compile time, they are resolved at runtime only.
113.

The abstract function definitions in derived classes is enforced at _________(a) Runtime(b) Compile time(c) Writing code time(d) Interpreting timeThe question was posed to me at a job interview.This key question is from Abstract Function topic in section Member Functions & its Types of Object Oriented Programming

Answer»

Correct option is (B) Compile time

The best I can explain: When the program is compiled, these definitions are checked if properly defined. This COMPILER also ensure that the FUNCTION is being defined by all the derived classes. HENCE we get a compile time error if not DONE.

114.

It is ____________________ to define the abstract functions.(a) Mandatory for all the classes in program(b) Necessary for all the base classes(c) Necessary for all the derived classes(d) Not mandatory for all the derived classesThis question was posed to me during an interview.I need to ask this question from Abstract Function topic in section Member Functions & its Types of Object Oriented Programming

Answer»

The correct option is (c) Necessary for all the derived classes

For EXPLANATION: The derived classes MUST DEFINE the abstract function of BASE class in their own body. This is a necessary CONDITION. Because the abstract functions doesn’t contain any definition in base class and hence becomes mandatory for the derived class to define them. All the functions in a program must have some definition.

115.

Which among the following is correct?(a) Abstract functions should not be defined in all the derived classes(b) Abstract functions should be defined only in one derived class(c) Abstract functions must be defined in base class(d) Abstract functions must be defined in all the derived classesI have been asked this question by my school principal while I was bunking the class.The question is from Abstract Function in portion Member Functions & its Types of Object Oriented Programming

Answer»

The correct OPTION is (d) ABSTRACT functions must be defined in all the DERIVED classes

For explanation: The abstract function are only declared in BASE classes and then has to be defined in all the derived classes. This allows all the derived classes to define own definition of any function whose declaration in base CLASS might be common to all the other derived classes.

116.

How are abstract functions different from the abstract functions?(a) Abstract must not be defined in base class whereas virtual function can be defined(b) Either of those must be defined in base class(c) Different according to definition(d) Abstract functions are fasterI had been asked this question in my homework.This intriguing question originated from Abstract Function in portion Member Functions & its Types of Object Oriented Programming

Answer» CORRECT OPTION is (a) Abstract MUST not be defined in base class whereas virtual function can be defined

Easiest explanation - The abstract functions are only declared in base class. Derived classes have to implement those functions in order to inherit that base class. The functions are always defined in derived classes only.
117.

Which among the following is true?(a) The abstract functions must be only declared in derived classes(b) The abstract functions must not be defined in derived classes(c) The abstract functions must be defined in base and derived class(d) The abstract functions must be defined either in base or derived classI have been asked this question in my homework.This interesting question is from Abstract Function in portion Member Functions & its Types of Object Oriented Programming

Answer» CORRECT option is (a) The ABSTRACT functions must be only declared in derived classes

Explanation: The abstract functions can’t be DEFINED in BASE class. They are to be defined in derived classes. It is a rule for abstract functions.
118.

Which among the following best defines the abstract methods?(a) Functions declared and defined in base class(b) Functions only declared in base class(c) Function which may or may not be defined in base class(d) Function which must be declared in derived classThe question was asked by my college director while I was bunking the class.My question is based upon Abstract Function topic in chapter Member Functions & its Types of Object Oriented Programming

Answer» RIGHT answer is (b) Functions only declared in base class

To EXPLAIN I WOULD SAY: The abstract functions must only be declared in base class. Their definitions are provided by the derived classes. It is a mandatory CONDITION.
119.

If virtual function of base class is redefined in derived class then ________________(a) It must be declared virtual in derived class also(b) It may or may not be declared virtual in derived class(c) It can must not be declared virtual in derived class(d) It must be declared normally in derived classThis question was addressed to me during an online exam.The doubt is from Virtual Functions in portion Member Functions & its Types of Object Oriented Programming

Answer» CORRECT OPTION is (b) It may or may not be declared virtual in DERIVED class

For explanation: The virtual functions may or may not be declared virtual in derived class. This is because if the overriding function defined in derived class is not declared virtual explicitly, the COMPILER makes it virtual IMPLICITLY.
120.

Which among the following is true?(a) A class may have virtual destructor but not virtual constructor(b) A class may have virtual constructor but not virtual destructor(c) A class may have virtual constructor and virtual constructor(d) A class may have either virtual destructor or virtual constructorI had been asked this question at a job interview.My query is from Virtual Functions topic in portion Member Functions & its Types of Object Oriented Programming

Answer»

Correct choice is (a) A CLASS may have virtual destructor but not virtual constructor

The explanation: Any class can CONTAIN virtual destructor. But is not possible to define a virtual constructor. The REASON behind is that the DESTRUCTORS can be overridden but CONSTRUCTORS should not be.

121.

It is __________ to redefine the virtual function in derived class.(a) Necessary(b) Not necessary(c) Not acceptable(d) Good practiceThis question was posed to me in an interview.My question comes from Virtual Functions in portion Member Functions & its Types of Object Oriented Programming

Answer»

Correct answer is (b) Not necessary

For explanation: It is not necessary to redefine the virtual FUNCTION in the derived class. If not defined, the base class function definition is USED but if defined, the intended definition is used ACCORDING to need. It is not about good coding PRACTICE as it should be REDEFINED only if needed.

122.

The virtual functions must be declared and defined in _____________ class and overridden in ___________ class.(a) Base, base(b) Derived, derived(c) Derived, base(d) Base, derivedThis question was posed to me in an interview.Query is from Virtual Functions topic in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Correct choice is (d) Base, derived

The best I can explain: The virtual FUNCTIONS must be declared and defined in base CLASS. The functions can be REDEFINED in derived class. If redefined in derived class then it OVERRIDES the base class function definition.

123.

Which among the following is true for virtual functions?(a) Prototype must be different in base and derived class(b) Prototype must be same in base class and derived class(c) Prototype must be given only in base class(d) Prototype must have different signature in base and derived classI had been asked this question by my college professor while I was bunking the class.I need to ask this question from Virtual Functions in section Member Functions & its Types of Object Oriented Programming

Answer»

Right option is (B) Prototype must be same in BASE class and derived class

The EXPLANATION is: The prototype must be the same. Because the function is to be OVERRIDDEN in the derived class. If the function prototype is different in derived class then it will not override the base class function and hence virtual function concept won’t work here.

124.

Which is a must condition for virtual function to achieve runtime polymorphism?(a) Virtual function must be accessed with direct name(b) Virtual functions must be accessed using base class object(c) Virtual function must be accessed using pointer or reference(d) Virtual function must be accessed using derived class object onlyThis question was addressed to me in an international level competition.This intriguing question comes from Virtual Functions topic in section Member Functions & its Types of Object Oriented Programming

Answer» RIGHT answer is (c) VIRTUAL function MUST be accessed using pointer or reference

Easy explanation - The virtual functions must be called using pointer or reference. This is MANDATORY so that the intended function GETS executed while resolving the method at runtime. The must not be any ambiguity between the method of parent class and derived class.
125.

Virtual functions can’t be made friend function of other classes.(a) True(b) FalseThe question was asked in exam.This question is from Virtual Functions in division Member Functions & its Types of Object Oriented Programming

Answer» CORRECT answer is (a) True

Explanation: The friend functions can ACCESS the PRIVATE members also. This may hinder the SECURITY of class members. This is why the functions should not be made friend functions of other class.
126.

Virtual functions can never be made _______________(a) Static function(b) Parameterized function(c) Default argument function(d) Zero parameter functionI have been asked this question in final exam.I want to ask this question from Virtual Functions in portion Member Functions & its Types of Object Oriented Programming

Answer» CORRECT OPTION is (a) Static function

To EXPLAIN: The virtual function must not be static. Those functions are the property of individual objects and not of a CLASS as a WHOLE. The functions should not be made common for all the objects of that class.
127.

In which access specifier should a virtual function be defined?(a) Private(b) Public(c) Protected(d) DefaultThis question was addressed to me by my school principal while I was bunking the class.The question is from Virtual Functions topic in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Right CHOICE is (b) Public

For explanation: The VIRTUAL functions must be defined in public section of a class. This is to ensure that the virtual function is available EVERYWHERE in the program. ALSO to avoid any error while RESOLVING the method.

128.

The resolving of virtual functions is done at ______________(a) Compile time(b) Interpret time(c) Runtime(d) Writing source codeThe question was posed to me in an interview for job.Origin of the question is Virtual Functions topic in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Correct option is (C) Runtime

Easy EXPLANATION - The resolving of virtual functions that are to be CALLED is done at run time. The base class and the derived classes may contain DIFFERENT definitions and different variables, so all these THINGS are resolved at run time and decided which function is to be called.

129.

Where the virtual function should be defined?(a) Twice in base class(b) Derived class(c) Base class and derived class(d) Base classI had been asked this question during an online exam.This interesting question is from Virtual Functions topic in division Member Functions & its Types of Object Oriented Programming

Answer»

The correct CHOICE is (d) BASE CLASS

The best EXPLANATION: The VIRTUAL function should be declared in base class. So that when the derived class inherits from the base class, the functions can be differentiated from the one in base class and another in derived class.

130.

Which keyword is used to declare virtual functions?(a) virtual(b) virt(c) anonymous(d) virtuallyI got this question during an interview.Origin of the question is Virtual Functions in division Member Functions & its Types of Object Oriented Programming

Answer»

The correct CHOICE is (a) virtual

To explain I would say: The virtual KEYWORD is used to declare virtual functions. Anonymous keyword is used with CLASSES and have a different meaning. The virtual functions are used to call the INTENDED function of the derived class.

131.

Virtual functions are mainly used to achieve _____________(a) Compile time polymorphism(b) Interpreter polymorphism(c) Runtime polymorphism(d) Functions code polymorphismI had been asked this question during an interview for a job.Question is from Virtual Functions topic in portion Member Functions & its Types of Object Oriented Programming

Answer»

Right answer is (C) Runtime POLYMORPHISM

Best explanation: It is used to achieve runtime polymorphism. The functions which are inherited and OVERRIDDEN, so at runtime the correct function is executed. The correct function call is made from the INTENDED class.

132.

Virtual function is ______ class function which expected to be redefined in ______ class, so that when reference is made to derived class object using pointer then we can call virtual function to execute ________ class definition version.(a) Base, derived, derived(b) Derived, Derived, Derived(c) Base, derived, base(d) Base, base, derivedThis question was addressed to me in unit test.I need to ask this question from Virtual Functions topic in chapter Member Functions & its Types of Object Oriented Programming

Answer»

Right answer is (a) Base, derived, derived

Easy explanation - The functions which MAY give rise to ambiguity due to INHERITANCE, can be declared virtual. So that whenever derived class object is referred using pointer or REFERENCE to the base class methods, we can still call the derived class methods using virtual FUNCTION. Hence this differentiates those methods from each other.

133.

What does a virtual function ensure for an object, among the following?(a) Correct method is called, regardless of the class defining it(b) Correct method is called, regardless of the object being called(c) Correct method is called, regardless of the type of reference used for function call(d) Correct method is called, regardless of the type of function being called by objectsThe question was posed to me in an online interview.This intriguing question originated from Virtual Functions in portion Member Functions & its Types of Object Oriented Programming

Answer»

The correct choice is (c) Correct method is called, regardless of the type of reference used for FUNCTION call

Best explanation: It is PROPERTY of the virtual function and one of their main use. Its use ensure that the correct method is called even though it is been called from different POINTER or REFERENCES. This also decreases chance of mistakes in PROGRAM.