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.

51.

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{}The question was posed to me by my college director while I was bunking the class.My query is from Template Class in portion Classes of Object Oriented Programming

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

Can default arguments be used with the template class?(a) Yes, in some special cases(b) Yes, always(c) No, it must satisfy some specific conditions first(d) No, it can’t be doneI have been asked this question by my college professor while I was bunking the class.The question is from Template Class in chapter Classes of Object Oriented Programming

Answer» RIGHT answer is (b) YES, always

To explain: The template CLASS can use DEFAULT arguments. This is used to specify the data type to be CONSIDERED if it is not specified while passing to the generic class. The default type will be used.
53.

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){}I have been asked this question by my school teacher while I was bunking the class.This key question is from Template Class topic in chapter Classes of Object Oriented Programming

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.

54.

A template class can have _____________(a) More than one generic data type(b) Only one generic data type(c) At most two data types(d) Only generic type of integers and not charactersI have been asked this question in my homework.Question is from Template Class topic in section Classes of Object Oriented Programming

Answer»

Right option is (a) More than one generic data type

Easy explanation - The template class can SUPPORT more than one data type. The only thing is to ADD all the data TYPES required in a LIST separated by comma within template SPECIFICATION.

55.

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 requiredI got this question in a job interview.This is a very interesting question from Abstract Class topic in section Classes of Object Oriented Programming

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.

56.

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 requiredThe question was posed to me in class test.Query is from Abstract Class in division Classes of Object Oriented Programming

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.

57.

It is _________________________ to have an abstract method.(a) Not mandatory for an static class(b) Not mandatory for a derived class(c) Not mandatory for an abstract class(d) Not mandatory for parent classThis question was addressed to me in an interview for internship.Asked question is from Abstract Class in portion Classes of Object Oriented Programming

Answer»

Right CHOICE is (c) Not mandatory for an abstract class

Explanation: Derived, PARENT and static CLASSES can’t have abstract METHOD (We can’t say what type of these classes is). And for abstract class it’s not mandatory to have abstract method. But if any abstract method is there inside a class, then class must be abstract type.

58.

Can abstract classes have static methods (Java)?(a) Yes, always(b) Yes, but depends on code(c) No, never(d) No, static members can’t have different valuesThe question was posed to me in an interview for internship.I'm obligated to ask this question of Abstract Class in section Classes of Object Oriented Programming

Answer»

The CORRECT option is (a) Yes, always

Explanation: There is no restriction on declaring STATIC methods. The only CONDITION is that the virtual functions must have some DEFINITION in the PROGRAM.

59.

Abstract class can’t be final in java.(a) True(b) FalseThe question was posed to me in an international level competition.My doubt is from Abstract Class topic in division Classes of Object Oriented Programming

Answer»

Right answer is (a) True

Easy EXPLANATION - If an abstract CLASS is made FINAL in java, it will stop the abstract class from being extended. And if the class is not getting extended, there won’t be ANOTHER class to IMPLEMENT the virtual functions. Due to this contradicting fact, it can’t be final in java.

60.

The abstract classes in java can _________________(a) Implement constructors(b) Can’t implement constructor(c) Can implement only unimplemented methods(d) Can’t implement any type of constructorI got this question by my college professor while I was bunking the class.My question comes from Abstract Class in chapter Classes of Object Oriented Programming

Answer»

The correct option is (a) Implement constructors

The best explanation: The abstract CLASSES in java can DEFINE a constructor. EVEN though instance can’t be created. But in this WAY, only during constructor CHAINING, constructor can be called. When instance of concrete implementation class is created, it’s known as constructor chaining.

61.

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 methodsThis question was posed to me in an interview for job.Origin of the question is Abstract Class in section Classes of Object Oriented Programming

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

Which among the following is an important use of abstract classes?(a) Header files(b) Class Libraries(c) Class definitions(d) Class inheritanceI have been asked this question in a job interview.This interesting question is from Abstract Class in section Classes of Object Oriented Programming

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.

63.

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 instanceThe question was asked in an online interview.The origin of the question is Abstract Class in division Classes of Object Oriented Programming

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.

64.

Abstract classes can ____________________ instances.(a) Never have(b) Always have(c) Have array of(d) Have pointer ofThis question was posed to me during an interview.I would like to ask this question from Abstract Class topic in portion Classes of Object Oriented Programming

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.

65.

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 correctlyThis question was posed to me in my homework.This key question is from Abstract Class topic in section Classes of Object Oriented Programming

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

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 classI had been asked this question in semester exam.The query is from Abstract Class in chapter Classes of Object Oriented Programming

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

If there is an abstract method in a class then, ________________(a) Class must be abstract class(b) Class may or may not be abstract class(c) Class is generic(d) Class must be publicThis question was posed to me in a job interview.My doubt is from Abstract Class in chapter Classes of Object Oriented Programming

Answer»

Right option is (a) Class MUST be ABSTRACT class

The EXPLANATION: It is a rule that if a class have even one abstract method, it must be an abstract class. If this rule was not made, the abstract methods WOULD have got skipped to get defined in some places which are UNDESIRABLE with the idea of abstract class.

68.

Can abstract class have main() function defined inside it?(a) Yes, depending on return type of main()(b) Yes, always(c) No, main must not be defined inside abstract class(d) No, because main() is not abstract functionThis question was posed to me in exam.This is a very interesting question from Abstract Class in chapter Classes of Object Oriented Programming

Answer»

Correct choice is (B) Yes, always

To explain: This is a property of abstract class. It can define main() FUNCTION inside it. There is no restriction on its definition and IMPLEMENTATION.

69.

Which among the following best describes abstract classes?(a) If a class has more than one virtual function, it’s abstract class(b) If a class have only one pure virtual function, it’s abstract class(c) If a class has at least one pure virtual function, it’s abstract class(d) If a class has all the pure virtual functions only, then it’s abstract classI had been asked this question during a job interview.I'm obligated to ask this question of Abstract Class topic in division Classes of Object Oriented Programming

Answer»

Correct answer is (c) If a class has at least one PURE VIRTUAL function, it’s ABSTRACT class

To EXPLAIN: The condition for a class to be called abstract class is that it must have at least one pure virtual function. The keyword abstract must be USED while defining abstract class in java.