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.

The string class deals with string of only character type.(a) True(b) FalseI got this question in an international level competition.This intriguing question comes from String Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

The correct option is (a) True

Easy EXPLANATION - The STRING class objects can be used for any string consisting of characters. The characters include NUMBERS, ALPHABETS and few special characters. String class is not necessary to be used but provides a HUGE set of inbuilt functions to make the string operations easier.

2.

If two arguments are passed to the indexOf() function then ___________________(a) Second argument indicates the occurrence number of specified character from starting(b) Second argument indicates the occurrence number of specified character from end(c) Second argument indicates the index of the character in first argument(d) Second argument indicates the index of the character from the last of the stringThis question was addressed to me in a national level competition.I need to ask this question from String Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

Right option is (a) Second ARGUMENT INDICATES the occurrence number of SPECIFIED character from starting

Explanation: The STRING may have more than one occurrence of a character. We use this function to get the index at which the specified number of times a specific character has OCCURRED in a string. For example, we can get the index of 5th occurrence of character “j” in a string.

3.

Function replace() accepts _____________ arguments.(a) 1(b) 2(c) 3(d) 4I got this question in semester exam.Enquiry is from String Class in chapter Inbuilt Classes of Object Oriented Programming

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.

4.

String trim() function is used to _______________________(a) Remove all the white spaces from the string(b) Remove white space from start of string(c) Remove white space at end of string(d) Remove white space from both the ends of stringThis question was posed to me during an online exam.My question is from String Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

The CORRECT OPTION is (d) Remove white space from both the ends of STRING

For explanation: The FUNCTION is used to remove any white space from both the ends of a given string. The white space include space, tab, next line etc. It will be removed both from the starting of string and from the end of string.

5.

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 uppercasesThe question was posed to me during an interview.Origin of the question is String Class topic in portion Inbuilt Classes of Object Oriented Programming

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.

6.

The compareTo() function is used to ________________(a) Compare strings value to string object(b) Compare string value to string value(c) Compare string object to another string object(d) Compare string object to another string valueThis question was posed to me in an internship interview.This intriguing question originated from String Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right CHOICE is (c) COMPARE string OBJECT to another string object

For explanation: The source and target must be objects of the string class. The compare is always CASE sensitive. To compare two string objects without case sensitivity then we can use compareToIgnoreCase() function.

7.

Function equals() is _______________ and equalIgnoreCase() is _________________(a) Case Insensitive, case insensitive(b) Case sensitive, Case insensitive(c) Case sensitive, case sensitive(d) Case insensitive, case sensitiveI have been asked this question during an interview.Origin of the question is String Class topic in section Inbuilt Classes of Object Oriented Programming

Answer»

Right answer is (b) CASE sensitive, Case insensitive

The best I can EXPLAIN: Both the functions RETURN Boolean VALUE. The function equal() is case sensitive and returns false even if a single character is case DIFFERENT in two strings. The other function ignores the case sensitivity and only checks if the spellings are same.

8.

The function lastIndexOf() is used to ___________________(a) Get the index of last occurrence of specified character in argument(b) Get the index of first occurrence of specified character in argument(c) Get the index of last occurrence of first character in string(d) Get the index of last occurrence of last character of stringThis question was addressed to me by my school teacher while I was bunking the class.This question is from String Class topic in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right choice is (a) Get the INDEX of last OCCURRENCE of specified character in argument

For EXPLANATION: The function is used to get the last occurrence index of a character present in a string. The return TYPE is char. Single character is returned. The function is used with a string object and the target character is passed as its argument.

9.

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 stringI have been asked this question during an online exam.Origin of the question is String Class topic in division Inbuilt Classes of Object Oriented Programming

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

If two index are given as argument to substring function then ___________________(a) String of length equal to sum of two arguments is returned(b) String starting from first index and of length equal to send argument(c) String starting from first index and of length equal to sum of two arguments(d) String starting from first index and ending at second index positionThis question was posed to me in my homework.This key question is from String Class in division Inbuilt Classes of Object Oriented Programming

Answer»

The CORRECT OPTION is (d) String starting from first index and ENDING at second index position

Easy explanation - A value of string type is returned from this function. The returned string is a substring that starts from the first ARGUMENT position, till the second index position. The indices must be less than the LENGTH of actual string.

11.

If only one parameter is passed to substring function then __________________(a) It returns the character at the specified position(b) It returns the string of length 1 from the specified index(c) It returns the string from specified index till the end(d) It returns the string from starting of string till the specified indexThis question was posed to me in examination.This intriguing question comes from String Class in section Inbuilt Classes of Object Oriented Programming

Answer»

The CORRECT option is (C) It returns the string from specified index till the END

To explain I would say: The substring FUNCTION returns a string value. The string is the substring starting from the specified index till the end. The substring function have to be called with the OBJECT of string class.

12.

Which is the function to get the character present at a particular index in the string?(a) char charAt(index);(b) char charIn(StringName);(c) char charAt(StringName);(d) char charIn(index);I got this question in homework.My enquiry is from String Class in portion Inbuilt Classes of Object Oriented Programming

Answer» RIGHT answer is (a) char charAt(index);

The explanation: The function can be called USING dot operator with the string object. Char is the return TYPE of the function to return the character at specified position. The index MUST be an integer value, less than the length of string.
13.

What does function length do in String class?(a) Returns length of string including null character(b) Returns length of string excluding null character(c) Returns length of substring(d) Returns size of string in bytesThis question was addressed to me in an international level competition.My question is based upon String Class in division Inbuilt Classes of Object Oriented Programming

Answer»

The CORRECT ANSWER is (b) Returns length of string excluding null character

Best explanation: The length function returns the length of string. The length is the number of characters in the string but the last null character is not COUNTED. The string length can be USED to loop through each character in the string.

14.

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;I have been asked this question in an interview for job.My query is from String Class in portion Inbuilt Classes of Object Oriented Programming

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.

15.

Which is a true statement for object of String class?(a) Object are immutable(b) Object are mutable(c) Object are created only once(d) Object can’t be createdI had been asked this question in a national level competition.The origin of the question is String Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

The correct option is (a) Object are IMMUTABLE

The explanation is: The object of string class are mostly immutable. This means that the String objects are CONSTANT. These can’t be CHANGED once created.

16.

Which among the following is a serialization descriptor for any class?(a) StreamClass(b) ObjectStreamClass(c) ObjectStream(d) StreamObjectClassI had been asked this question in examination.The above asked question is from IO Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

Right choice is (b) OBJECTSTREAMCLASS

To explain: The ObjectStreamClass object can be created to handle serializations. The class is provided specially for the serializations. It is descriptor LIKE we have a file descriptor to handle/access FILES.

17.

RandomAccessFile can be used to _______________________(a) Read from a random access file(b) Write to a random access file(c) Read and write to a random access file(d) Restricts read and write to a random access fileI got this question in class test.I need to ask this question from IO Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right option is (c) Read and write to a random access file

To explain I WOULD SAY: The RandomAccessFile class INSTANCE can be created to HANDLE input and output operations to a random access file. It first checks the permissions on the file and then any required operation can be DONE on a random access file. Comparatively faster than other files access.

18.

PushBackReader allows the streams to be pushed back to the stream.(a) True(b) FalseThe question was posed to me in a national level competition.My question is based upon IO Class topic in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right CHOICE is (a) True

Easy explanation - The PushBackReader allows the character streams handling. The MAIN feature is that the STREAM can be PUSHED back to the stream. This is USED in special cases of handling input stream.

19.

Which exception handler can be used when character encoding is not supported?(a) UnsupportedException(b) UnsupportedEncodingException(c) SupportException(d) EncodingExceptionThis question was posed to me in an online quiz.My question is from IO Class topic in section Inbuilt Classes of Object Oriented Programming

Answer»

Correct ANSWER is (B) UnsupportedEncodingException

The explanation is: The encoding that is UNSUPPORTED in a system can be handled. The EXCEPTION handler is UnSupportedEncodingException class. An object of this class can be created which will catch the exception and handle it.

20.

StringReader handles _____________________(a) Any character stream(b) A character stream whose source is an array(c) A character stream whose source is character array(d) A character stream whose source is String onlyI had been asked this question in an interview.My doubt is from IO Class topic in section Inbuilt Classes of Object Oriented Programming

Answer»

Right ANSWER is (d) A character stream whose source is STRING only

Explanation: The StringReader can only WORK with the string type data. Even if a character array is given, it MIGHT produce some errors in code. Hence only the string values can be handled properly.

21.

Which class can handle IO class interrupt?(a) ExceptionIO(b) InteruptedIO(c) InteruptedIOException(d) IOInteruptExceptionI have been asked this question by my school principal while I was bunking the class.Origin of the question is IO Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right choice is (C) InteruptedIOException

Explanation: The only class which handles the IO class INTERRUPTS is InteruptedIOException class. This class is SPECIALLY provided to HANDLE any case that INVOLVES the execution interrupt.

22.

Reader class is _________________(a) Used to read from files(b) Abstract class to read character streams(c) Abstract class to input character streams(d) Used to take input from standard input streamThe question was posed to me by my college director while I was bunking the class.The query is from IO Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

Correct option is (b) ABSTRACT CLASS to read character streams

For explanation: The Reader class is an abstract class that can be used to read characters STREAM. It can’t be used for any kind of input. It can just read the EXISTING data.

23.

Which class among the following makes incorrect assumptions?(a) LineNumberInputStream(b) LineNumberReader(c) LineReader(d) LineBufferI got this question during an interview for a job.Question is taken from IO Class in portion Inbuilt Classes of Object Oriented Programming

Answer»

Right OPTION is (a) LineNumberInputStream

Easy EXPLANATION - The LineNumberInputStream class makes false assumptions. The false assumption is that it assumes, all the byte data is a CHARACTER. Which is actually not the case, INSTEAD the character have one byte MEMORY space.

24.

What does FilePermission class do?(a) This class is used to give permission rights to a file(b) This class is used to restrict the use of permissions(c) This class is used to represent device access permissions(d) This class is used to represent file access permissionsI had been asked this question in an interview.This interesting question is from IO Class topic in division Inbuilt Classes of Object Oriented Programming

Answer»

Right answer is (d) This class is used to REPRESENT file access permissions

For explanation: The FilePermission can’t GET access to the device access permissions. The PERMISSION is given to a file when it is CREATED or otherwise when a privileged user changes it. Then these permission rights can be accessed USING the FilePermission class.

25.

FileInputStream _________________________(a) Gets the input stream from any device file(b) Gets the input stream from any open socket(c) Gets the input stream from any cache(d) Gets the input stream from any open file onlyThis question was addressed to me in unit test.I'm obligated to ask this question of IO Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

The correct answer is (d) Gets the input STREAM from any open file only

Explanation: The most specific answer is that the FileInputStream can only be used for the opened files. The class can work only for the file TYPE. No SOCKET or another source are allowed to be accessed.

26.

What is a FileDescriptor?(a) A handle for machine specific structure of an open file(b) A handle for program specific structure of an open file(c) A handle for compiler specific structure of an open file(d) A handle for representing device files structureThe question was asked in homework.I want to ask this question from IO Class topic in portion Inbuilt Classes of Object Oriented Programming

Answer»

The correct ANSWER is (a) A HANDLE for machine specific structure of an open FILE

Easiest explanation - The machine specific structure of an open file have to be handled in some special ways. FileDescriptor class can handle those FILES. The FileDescriptor can also handle open socket, another SOURCE, sink of bytes.

27.

File class is ____________________________(a) An abstract of file representation only(b) An abstract of path names only(c) An abstract which can be used to represent path names or file(d) An abstract which can represent a file in any formatThis question was addressed to me during an interview.Enquiry is from IO Class topic in portion Inbuilt Classes of Object Oriented Programming

Answer»

Correct answer is (C) An abstract which can be used to represent path names or file

Easy EXPLANATION - The File class is made to operate with the files. The file can be of any type. All the input and OUTPUT operations that have to be performed on a file can be DONE using File class object.

28.

Which among the following class contains the methods to access character based console device?(a) Console(b) File(c) Device(d) PipeThe question was posed to me during an interview.Enquiry is from IO Class in chapter Inbuilt Classes of Object Oriented Programming

Answer»

The correct OPTION is (a) Console

To explain I would say: The Console class contains the METHODS to access the character BASED devices. The devices which can stream the data as character set. All those devices can be made use of by USING the methods of class Console.

29.

IO class provides input and output through ______________________(a) Data streams(b) Serialization(c) File system(d) Data streams, serialization and file systemThe question was posed to me in an interview for job.This is a very interesting question from IO Class topic in chapter Inbuilt Classes of Object Oriented Programming

Answer»

Correct option is (d) DATA streams, SERIALIZATION and file system

To explain I would say: The IO classes are MADE such that those can support the input and output from any TYPE of source or destination. The input can be taken from system file and standard input and also some special devices if conned. Same is CASE to show the output.

30.

What is the use of IO class?(a) To handle all the input operations(b) To handle all the output operations(c) To handle all the input and output operations(d) To handle all the input and output to the standard inputI got this question in unit test.Asked question is from IO Class in portion Inbuilt Classes of Object Oriented Programming

Answer» CORRECT option is (c) To handle all the input and output operations

Easiest explanation - The IO class provides FUNCTIONS that can be used to handle input and output operations. All the inputs from standard input and standard output, and also from the files can be handled. This GIVES the FLEXIBILITY to make the programs more user friendly.
31.

Which package contains the utility classes?(a) java.lang(b) java.utility(c) java.util(d) java.ioThis question was posed to me during an online interview.My doubt stems from Inbuilt Classes in section Inbuilt Classes of Object Oriented Programming

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.

32.

Which is not a System class variable?(a) err(b) out(c) in(d) putThis question was posed to me in final exam.I need to ask this question from Inbuilt Classes in section Inbuilt Classes of Object Oriented Programming

Answer»

The correct answer is (d) PUT

For explanation: Put is not a SYSTEM CLASS variable. The most GENERAL and BASIC variables are err, out and in. The variables can handle most of the tasks performed in a program.

33.

What does load(String)::= function do, in System class?(a) Loads dynamic library for a path name(b) Loads all the dynamic libraries(c) Loads all the Number in string format(d) Loads the processor with calculationsI had been asked this question in an online quiz.My question is taken from Inbuilt Classes topic in section Inbuilt Classes of Object Oriented Programming

Answer» RIGHT answer is (a) Loads dynamic library for a path name

Explanation: Only the SPECIFIED path NAMED dynamic libraries are loaded. All the dynamic libraries can’t be loaded at a time. Hence we use this function for specific libraries.
34.

Which class contain runFinalization() method?(a) Finalize(b) System(c) Final(d) SystemFinalI got this question during an online exam.My enquiry is from Inbuilt Classes topic in section Inbuilt Classes of Object Oriented Programming

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.

35.

Which function should be used to exit from the program that is provided by System class?(a) exit(int);(b) gc();(c) terminate();(d) halt();I have been asked this question in unit test.I want to ask this question from Inbuilt Classes topic in section Inbuilt Classes of Object Oriented Programming

Answer»

The correct answer is (a) exit(INT);

To explain: The exit function should be used to terminate the program. The function is PASSED with an ARGUMENT. The argument INDICATED the type of error occurred.

36.

Number class can’t manipulate ____________________(a) Integer values(b) Float values(c) Byte values(d) Character valuesThis question was addressed to me during an online exam.This intriguing question comes from Inbuilt Classes in portion Inbuilt Classes of Object Oriented Programming

Answer» CORRECT answer is (d) Character values

Explanation: The Number class is used to WORK with all the number type of values. The integers, FLOAT, double, byte etc. are all number type values. Character is not a number VALUE.
37.

Which attribute can be used to get the size of an array?(a) Size.Array(b) Array.Size(c) Array_name.length(d) length.Array_nameI had been asked this question during an online interview.This intriguing question originated from Inbuilt Classes in section Inbuilt Classes of Object Oriented Programming

Answer»

Correct ANSWER is (c) Array_name.length

Easy explanation - The array name is given of which the length have to be calculated. The array length is stored in the attribute length. Hence we ACCESS it using dot OPERATOR.

38.

DataInputStream is derived from ______________________(a) StreamingInput(b) StreamedInput(c) StreameInput(d) StreamInputI got this question in an internship interview.The origin of the question is Inbuilt Classes topic in portion Inbuilt Classes of Object Oriented Programming

Answer» CORRECT option is (d) StreamInput

Explanation: The DataInputStream is more SPECIFIC class for operating on specific type of DATA inputs. This is USED to read data of specific type. The same can be used to read data in a specific FORMAT.
39.

What is the use of Math class?(a) To use the mathematical functions with strings(b) To use the mathematical functions(c) To suppress the use of mathematical functions(d) To complex the calculationsThis question was addressed to me by my school teacher while I was bunking the class.This intriguing question comes from Inbuilt Classes in section Inbuilt Classes of Object Oriented Programming

Answer» RIGHT option is (B) To USE the mathematical functions

Best explanation: The Math class is provided with some special functions. These functions can be used to CALCULATE and get result of some special and usual mathematical functions. We don’t have to write the code to calculate the trigonometric function results, instead we can use Math functions.
40.

Which statement is true for the Array class?(a) Arrays can have variable length(b) The length array can be changed(c) Each class has an associated Array class(d) Arrays can contain different type of valuesThe question was posed to me in an online interview.I would like to ask this question from Inbuilt Classes topic in division Inbuilt Classes of Object Oriented Programming

Answer»

Right option is (c) Each CLASS has an associated ARRAY class

The best I can EXPLAIN: The Array class is associated with all the other classes. This GIVES us the flexibility to declare an array of any type. The INDEX goes from 0 to n, where n is some fixed size for array.

41.

What is the InputStream class meant for?(a) To handle all input streams(b) To handle all output streams(c) To handle all input and output streams(d) To handle only input from fileThe question was asked in an interview for internship.My question is taken from Inbuilt Classes in division Inbuilt Classes of Object Oriented Programming

Answer» RIGHT option is (a) To handle all input streams

Easy explanation - The INPUTSTREAM is an inbuilt class which is used to handle all the TASKS related to input handling. This class extends input from keyboard or FILE or any other possible input stream.
42.

Which among the following not an inbuilt class in C++?(a) System(b) Color(c) String(d) FunctionsI have been asked this question in quiz.I would like to ask this question from Inbuilt Classes topic in section Inbuilt Classes of Object Oriented Programming

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

What doesn’t inbuilt classes contain?(a) Function prototype(b) Function declaration(c) Function definitions(d) ObjectsI had been asked this question by my school teacher while I was bunking the class.Question is from Inbuilt Classes in chapter Inbuilt Classes of Object Oriented Programming

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.

44.

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 alwaysThe question was posed to me in examination.This interesting question is from Inbuilt Classes topic in portion Inbuilt Classes of Object Oriented Programming

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.

45.

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 userI have been asked this question in a job interview.The question is from Inbuilt Classes in portion Inbuilt Classes of Object Oriented Programming

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.