InterviewSolution
Saved Bookmarks
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. |
Which among the following handles the undefined class in program?(a) ClassNotFound(b) NoClassException(c) ClassFoundException(d) ClassNotFoundException |
|
Answer» The correct option is (d) ClassNotFoundException The best I can explain: It is the exception handler that handles the exceptions when the class used is not found in the program. This is done to handle all the undefined class exceptions. This can be due to a command line error. |
|
| 2. |
Which among the following is true for class exceptions?(a) Only base class can give rise to exceptions(b) Only derived class can give rise to exceptions(c) Either base class or derived class may produce exceptions(d) Both base class and derived class may produce exceptions |
|
Answer» Correct answer is (d) Both base class and derived class may produce exceptions For explanation: It’s not mandatory that either base class or derived class can give rise to exceptions. The exceptions might get produced from any class. The exceptions depends on code. |
|
| 3. |
Since which version of java is multiple exception catch was made possible?(a) Java 4(b) Java 5(c) Java 6(d) Java 7 |
|
Answer» The correct answer is (d) Java 7 Best explanation: None of the languages used to support multiple exception catch in a single catch block. Since java 7 the feature was added to catch more than one exceptions in one catch block. |
|
| 4. |
If both base and derived class caught exceptions ______________(a) Then catch block of derived class must be defined before base class(b) Then catch block of base class must be defined before the derived class(c) Then catch block of base and derived classes doesn’t matter(d) Then catch block of base and derived classes are not mandatory to be defined |
|
Answer» The correct option is (a) Then catch block of derived class must be defined before base class The explanation is: It is a condition for writing the catch blocks for base and derived classes. It is mandatory to write derived class catch block first because the errors produced by the derived class must be handled first. |
|
| 5. |
If catching of base class exception is done before derived class in C++ ________________(a) It gives compile time error(b) It doesn’t run the program(c) It may give warning but not error(d) It always gives compile time error |
|
Answer» Correct choice is (c) It may give warning but not error Easy explanation - The compiler in C++ doesn’t identify this as compile time error and allows the execution of the program. But, the compiler may give some warning related to the catch block sequence or code unreachable. |
|
| 6. |
If classes produce some exceptions, then ______________________(a) Their respective catch block must be defined(b) Their respective catch blocks are not mandatory(c) Their catch blocks should be defined inside main function(d) Their catch blocks must be defined at the end of program |
|
Answer» Correct choice is (a) Their respective catch block must be defined The explanation: The catch blocks must be defined. This is to ensure that all the exceptions related to the classes are handled by the program code and the program doesn’t terminate unexpectedly. |
|
| 7. |
Any changes made to static data member from one member function _____________(a) Is reflected to only the corresponding object(b) Is reflected to all the variables in a program(c) Is reflected to all the objects of that class(d) Is constant to that function only |
|
Answer» The correct choice is (c) Is reflected to all the objects of that class The best explanation: The changes made from any function to static data member will be a common change for all the other objects also. If the change is made with respect to one object and change is printed from another object, the result will be same. |
|
| 8. |
The static data member ______________________(a) Must be defined inside the class(b) Must be defined outside the class(c) Must be defined in main function(d) Must be defined using constructor |
|
Answer» Right option is (b) Must be defined outside the class Explanation: The static data members must be defined outside the class. Since these are common to all the objects and should be created only once, they must not be defined in the constructor. |
|
| 9. |
If a catch block accepts more than one exceptions then __________________(a) The catch parameters are not final(b) The catch parameters are final(c) The catch parameters are not defined(d) The catch parameters are not used |
|
Answer» Right answer is (b) The catch parameters are final To explain: The catch parameters are made final. This is to ensure that the parameters are not changed inside the catch block. Hence those retain their values. |
|
| 10. |
Which condition among the following might result in memory exception?(a) False if conditions(b) Nested if conditions that are all false(c) Infinite loops(d) Loop that runs exactly 99 times |
|
Answer» The correct answer is (c) Infinite loops To explain I would say: The infinite loops doesn’t stop running once started. There must be a way to stop the loop but that is always an improper termination. Infinite loops may keep on using more memory and hence would result in memory error. |
|
| 11. |
To catch more than one exception in one catch block, how are the exceptions separated in the syntax?(a) Vertical bar(b) Hyphen(c) Plus(d) Modulus |
|
Answer» Correct choice is (a) Vertical bar To explain I would say: Just the way we separate the arguments in a function definition using comma. Here we separate the exceptions by using a vertical bar or we call it pipe symbol sometimes. This is just a convention followed to separate different exception list. |
|
| 12. |
Which is the correct syntax for declaring static data member?(a) static mamberName dataType;(b) dataType static memberName;(c) memberName static dataType;(d) static dataType memberName; |
|
Answer» The correct choice is (d) static dataType memberName; For explanation: The syntax must firstly be mentioned with the keyword static. Then the data type of the member followed by the member name should be given. This is general form of declaring static data members. |
|
| 13. |
The syntax for defining the static data members is __________(a) dataType className :: memberName = value;(b) dataType className : memberName = value;(c) dataType className . memberName = value;(d) dataType className -> memberName =value; |
|
Answer» Correct answer is (a) dataType className :: memberName = value; To explain I would say: The syntax doesn’t contain the static keyword. Since it is already been declared as static inside the class. The data type and the corresponding class name must be there to allocate the variable to a class. The value is assigned using scope resolution operator for the member name. |
|
| 14. |
Which among the following is wrong syntax related to static data members?(a) className :: staticDataMember;(b) dataType className :: memberName =value;(c) static dataType memberName;(d) className : dataType -> memberName; |
|
Answer» Correct answer is (d) className : dataType -> memberName; Explanation: The syntax given in option d doesn’t belong to any particular declaration or definition. First one is to access the static members using the class name. Second is to define the static data outside the class. Third syntax id to declare a data member as static in a class. |
|
| 15. |
If object of class are created, then the static data members can be accessed ____________(a) Using dot operator(b) Using arrow operator(c) Using colon(d) Using dot or arrow operator |
|
Answer» Right answer is (d) Using dot or arrow operator For explanation: The static data members can be accessed in usual way as other members are accessed using the objects. The dot operator is used generally. Arrow can be used with the pointers. |
|
| 16. |
Which is correct syntax to access the static member functions with class name?(a) className . functionName;(b) className -> functionName;(c) className : functionName;(d) className :: functionName; |
|
Answer» Correct option is (d) className :: functionName; Easiest explanation - The scope resolution operator must be used to access the static member functions with class name. This indicates that the function belongs to the corresponding class. |
|
| 17. |
The static member functions ____________________(a) Can be called using class name(b) Can be called using program name(c) Can be called directly(d) Can’t be called outside the function |
|
Answer» The correct choice is (a) Can be called using class name For explanation: The static members can be accessed using class name also. This is because the static members remain common to all the objects. Hence objects are not required. |
|
| 18. |
Which among the following can’t be used to access the members in any way?(a) Scope resolution(b) Arrow operator(c) Single colon(d) Dot operator |
|
Answer» Correct answer is (c) Single colon To explain I would say: The single colon can’t be used in any way in order to access the static members of a class. Other symbols can be used according to the code and need. |
|
| 19. |
Which keyword should be used to declare the static member functions?(a) static(b) stat(c) const(d) common |
|
Answer» Right answer is (a) static Easy explanation - The member functions which are to be made static, must be preceded with the keyword static. This indicates the compiler to make the functions common to all the objects. And a new copy is not created with each of the new object. |
|
| 20. |
We can use the static member functions and static data member __________________(a) Even if class object is not created(b) Even if class is not defined(c) Even if class doesn’t contain any static member(d) Even if class doesn’t have complete definition |
|
Answer» Correct option is (a) Even if class object is not created Explanation: The static members are property of class as a whole. There is no need of specific objects to call static members. Those can be called directly or with class name. |
|
| 21. |
The keyword static is used _______________(a) With declaration inside class and with definition outside the class(b) With declaration inside class and not with definition outside the class(c) With declaration and definition wherever done(d) With each call to the member function |
|
Answer» Correct choice is (b) With declaration inside class and not with definition outside the class The best I can explain: The keyword is used only inside the class while declaring the static member. Outside the class, only definition with proper syntax is given. There is no need of specifying the keyword static again. |
|
| 22. |
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 values |
|
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. |
|
| 23. |
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(); |
|
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. |
|
| 24. |
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 calculations |
|
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. |
|
| 25. |
Which is not a System class variable?(a) err(b) out(c) in(d) put |
|
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. |
|
| 26. |
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 calculations |
|
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. |
|
| 27. |
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 string |
|
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. |
|
| 28. |
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 position |
|
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. |
|
| 29. |
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 bytes |
|
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. |
|
| 30. |
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 value |
|
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. |
|
| 31. |
Which class can handle IO class interrupt?(a) ExceptionIO(b) InteruptedIO(c) InteruptedIOException(d) IOInteruptException |
|
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. |
|
| 32. |
Which class among the following makes incorrect assumptions?(a) LineNumberInputStream(b) LineNumberReader(c) LineReader(d) LineBuffer |
|
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. |
|
| 33. |
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 sensitive |
|
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. |
|
| 34. |
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 structure |
|
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. |
|
| 35. |
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 only |
|
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. |
|
| 36. |
DataInputStream is derived from ______________________(a) StreamingInput(b) StreamedInput(c) StreameInput(d) StreamInput |
|
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. |
|
| 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_name |
|
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. |
Number class can’t manipulate ____________________(a) Integer values(b) Float values(c) Byte values(d) Character values |
|
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. |
|
| 39. |
Which exception handler can be used when character encoding is not supported?(a) UnsupportedException(b) UnsupportedEncodingException(c) SupportException(d) EncodingException |
|
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. |
|
| 40. |
Which among the following class contains the methods to access character based console device?(a) Console(b) File(c) Device(d) Pipe |
|
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. |
|
| 41. |
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 file |
|
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. |
|
| 42. |
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 format |
|
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. |
|
| 43. |
IO class provides input and output through ______________________(a) Data streams(b) Serialization(c) File system(d) Data streams, serialization and file system |
|
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. |
|
| 44. |
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 permissions |
|
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. |
|
| 45. |
Which among the following is a serialization descriptor for any class?(a) StreamClass(b) ObjectStreamClass(c) ObjectStream(d) StreamObjectClass |
|
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. |
|
| 46. |
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 index |
|
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. |
|
| 47. |
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 input |
|
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. |
|
| 48. |
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 string |
|
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. |
|
| 49. |
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 created |
|
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. |
|
| 50. |
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); |
|
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. |
|