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.

How to declare an object of class String?(a) String object_Name = value;(b) String object_name = new;(c) String object_name= new value;(d) String object_name= value new;

Answer» The correct answer is (a) String object_Name = value;

The best I can explain: The class name String is given. And then the object name is mentioned. There are two ways to declare and initialize the string. Either by giving direct string value or by using new keyword. But if new operator is used, constructor of String class have to be called. From the given options, the direct string value declaration is correct.
52.

Which class contain runFinalization() method?(a) Finalize(b) System(c) Final(d) SystemFinal

Answer» Correct answer is (b) System

The explanation: The runFinalization() Function is defined in the System class. The function is used to finalize an object which undergo destruction. The action is required to terminate the object properly.
53.

String class have a concat() function that is used to _____________________(a) Replace old string by new string(b) Add two strings(c) Append one string at end of another string(d) Remove a string from end of one string

Answer» Right choice is (c) Append one string at end of another string

The explanation is: The concat function is used to append string into another string. The new string is always appended at the end of source string. The target string is appended as it is and the whole string is then ended by null character.
54.

Function replace() accepts _____________ arguments.(a) 1(b) 2(c) 3(d) 4

Answer» The correct option is (b) 2

The explanation is: The first argument is the target character. This target character will be replaced by another character. The new character is the second argument to the function. Only the characters can be passed as argument, not a string.
55.

String class provides function toUpper() to _____________________(a) Convert first character to uppercase(b) Convert last character to uppercase(c) Convert the whole string characters to uppercase(d) Convert uppercase to lower and lower to uppercases

Answer» Correct option is (c) Convert the whole string characters to uppercase

To explain: The function is used to convert each character of the string. If the character is already uppercase then it remains the same. But if some character is in lowercase then it will be converted to uppercase.
56.

What doesn’t inbuilt classes contain?(a) Function prototype(b) Function declaration(c) Function definitions(d) Objects

Answer» The correct choice is (c) Function definitions

The best explanation: The classes contain the definitions of the special functions that are provided for the programmers use. Those functions can be used to make the programming easy and to reuse the already existing code.
57.

Which among the following not an inbuilt class in C++?(a) System(b) Color(c) String(d) Functions

Answer» Correct option is (d) Functions

To explain: There is no inbuilt class named function in java. The others are classes already provided in java. All those classes contain some special functions to be used in programming.
58.

Inbuilt class __________________________(a) Must be included before use(b) Are not necessary to be included for use(c) Are used by the compiler only(d) Can be modified by programmer always

Answer» The correct option is (a) Must be included before use

The best explanation: The inbuilt classes must be included in the program. Whenever some functions are used, they must have a declaration before use. The same is the case with classes.
59.

Which package contains the utility classes?(a) java.lang(b) java.utility(c) java.util(d) java.io

Answer» Right option is (c) java.util

Easiest explanation - The package java.util contains all the utility classes. This package also contains generic data structures, date, time etc. These can be used in any java program, you just have to include java.util package.
60.

What are inbuilt classes?(a) The predefined classes in a language(b) The classes that are defined by the user(c) The classes which are meant to be modified by the user(d) The classes which can’t be used by the user

Answer» Correct choice is (a) The predefined classes in a language

To explain I would say: The classes that are already provided in a programming language for use are inbuilt classes. These classes provide some functions or objects that can be used by the programmer for easier code.
61.

Which language can use inheritance with local classes?(a) Kotlin(b) Java(c) SmallTalk(d) SAP ABAP

Answer» Correct option is (d) SAP ABAP

The explanation: Other language might support inheritance with local classes but those doesn’t provide all the proper features of inheritance. Language SAP ABAP provides a way to implement inheritance with local classes efficiently.
62.

All the member functions of local classes are __________ by default.(a) Static(b) Inline(c) Abstract(d) Virtual

Answer» Correct option is (c) Abstract

The best I can explain: All the members are defined inside the class body. And when the member functions are defined inside the class body, they are made inline by default. If the definition is too complex, those are made normal functions.
63.

Which among the following is the main advantage of using local classes?(a) Make program more efficient(b) Makes program execution faster(c) Helps to add extra functionality to a function(d) Helps to add more members to a function

Answer» The correct option is (c) Helps to add extra functionality to a function

Easy explanation - The closest answer is to add more functionalities to a function or to make some specific functions to be generic. Adding more members to a function can be done directly but to add some special functionality that are encapsulated, can be done using local classes.
64.

How many local classes can be defined inside a single function?(a) Only 1(b) Only 3(c) Only 5(d) As many as required

Answer» Correct answer is (d) As many as required

The explanation: The local classes can be defined as required. There is no restriction on the number of local classes that can be defined inside a function. But all those classes must follow the rules and restrictions.
65.

How many categories are nested classes divided into?(a) 2(b) 3(c) 4(d) 5

Answer» Correct choice is (a) 2

The explanation: The nested classes are divided into two main categories. Namely, Static and non-static. The categories define how the classes can be used inside another class.
66.

Non-static nested classes have access to _____________ from enclosing class.(a) Private members(b) Protected members(c) Public members(d) All the members

Answer» The correct option is (d) All the members

The explanation is: The non-static nested class can access all the members of the enclosing class. All the data members and member functions can be accessed from the nested class. Even if the members are private, they can be accessed.
67.

What are local classes?(a) Classes declared inside a package(b) Classes declared inside a function(c) Classes declared inside a class(d) Classes declared inside structure

Answer» The correct option is (b) Classes declared inside a function

The explanation: The classes declared inside a package are available to all the functions and classes, hence can’t be called local. This is somewhat similar concept that we use to denote variables of a function. The classes declared inside functions will be local to them.
68.

A member function can _______________ of the same class.(a) Call other member functions(b) Call only private member functions(c) Call only static member functions(d) Call only const member functions

Answer» Correct option is (a) Call other member functions

For explanation: We can call one function inside another function to access some data of class. A public member function can be used to call a private member function which directly manipulates the private data of class.
69.

Which among the following is not possible for member function?(a) Access protected members of parent class(b) Definition without return type(c) Access public members of subclass(d) Access static members of class

Answer» Right choice is (c) Access public members of subclass

To explain: A member function of a class can only have the access to the members of its own class and parent classes if inheritance used. Otherwise a member function can never access the members of a subclass. Accessing static members of a class is possible by normal and static member functions.
70.

For overloading “( )”, “[ ]” or “->” operators, a class __________(a) Must use static member functions(b) Must use non-static member functions(c) Must be non-static member and should not be friend of class(d) Must use static member function or a friend member function

Answer» The correct answer is (c) Must be non-static member and should not be friend of class

To explain I would say: For overloading those operators for a class, the class must use non-static member function so that doesn’t remain common to all the objects, and each object can use it independently. The friend functions is also restricted so as to keep the security of data.
71.

What is the term used to indicate the variable and constants of a class?(a) Data members(b) Variables of class(c) Data characters(d) Constants

Answer» Right answer is (a) Data members

The best explanation: The variables inside a class are termed data members of the class. It is not a mandatory rule but variables are used to refer to usual variables used in functions or globally. The term is given because the values stored in those variables represent some kind of data related to class.
72.

Data members ________________ (C++)(a) Can be initialized with declaration in classes(b) Can be initialized only with help of constructors(c) Can be initialized either in declaration or by constructor(d) Can’t be initialized

Answer» The correct choice is (b) Can be initialized only with help of constructors

The explanation: The data members are not property of class, those are property of the instances of the class. And the memory for the data members are not reserved until a constructor is called. Hence we use constructors for their initialization after the memory is reserved.
73.

Can two different functions have local class with same name?(a) Yes, since local(b) No, names must be different(c) No, scope doesn’t work here(d) No, ambiguity arises

Answer» The correct answer is (a) Yes, since local

For explanation: The local classes can have same name if they belong to different functions. The classes would be local to those specific functions and hence can have same name. This is same as that of local variables concept.
74.

The static member functions _______________(a) Can’t be declared const(b) Can’t be declared volatile(c) Can’t be declared const or volatile(d) Can’t be declared const, volatile or const volatile

Answer» Right option is (d) Can’t be declared const, volatile or const volatile

For explanation: The static member functions can’t be made const, since any object or class itself should be capable of making changes to the function. And the function must retain all changes common to all the objects.
75.

Which among the following is not applicable for the static member functions?(a) Variable pointers(b) void pointers(c) this pointer(d) Function pointers

Answer» Correct choice is (c) this pointer

The best explanation: Since the static members are not property of objects, they doesn’t have this pointer. Every time the same member is referred from all the objects, hence use of this pointer is of no use.
76.

If static data member are made inline, ______________(a) Those should be initialized outside the class(b) Those can’t be initialized with the class(c) Those can be initialized within the class(d) Those can’t be used by class members

Answer» Right choice is (c) Those can be initialized within the class

Explanation: Since the members are created once and are common for all the instances, those can be initialized inside the class. Those doesn’t change with each object being created hence can be defined inside the class once for all.
77.

The static data member _________________(a) Can be mutable(b) Can’t be mutable(c) Can’t be integer(d) Can’t be characters

Answer» Correct answer is (b) Can’t be mutable

To explain I would say: The static data members can never be mutable. There copies are not made. Since those are common and created only once.