You are on page 1of 22

Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

Inbuilt Classes - Object Oriented


Programming Questions and
Answers
by Manish
6-7 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on “Inbuilt
Classes”.

1. 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
View Answer

Answer: a
Explanation: 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.

2. Inbuilt class __________________________


a) Must be included before use
b) Are not necessary to be included for use

1 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

c) Are used by the compiler only


d) Can be modified by programmer always
View Answer

Answer: a
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 case with
classes.

3. What doesn’t inbuilt classes contain?


a) Function prototype
b) Function declaration
c) Function definitions
d) Objects
View Answer

Answer: c
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.

4. Which among the following not an inbuilt class in C++?


a) System
b) Color
c) String
d) Functions
View Answer

Answer: d
Explanation: There is no inbuilt class named function in
java. The others are classes already provided in java. All

2 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

those classes contain some special functions to be used in


programming.

5. What is 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 file
View Answer

Answer: a
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.

6. Which statement is true for 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
View Answer

Answer: c
Explanation: The Array class is associated with all the other
classes. This gives us flexibility to declare an array of any
type. The index goes from 0 to n, where n is some fixed
size for array.

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

3 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

d) To complex the calculations


View Answer

Answer: b
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.

8. DataInputStream is derived from


______________________
a) StreamingInput
b) StreamedInput
c) StreameInput
d) StreamInput
View Answer

Answer: d
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.

9. 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
View Answer

Answer: c

4 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

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.

10. Number class can’t manipulate


____________________
a) Integer values
b) Float values
c) Byte values
d) Character values
View Answer

Answer: d
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.

11. 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();
View Answer

Answer: a
Explanation: 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.

12. Which class contain runFinalization() method?


a) Finalize

5 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

b) System
c) Final
d) SystemFinal
View Answer

Answer: b
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.

13. 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
View Answer

Answer: a
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.

14. Which is not a System class variable?


a) err
b) out
c) in
d) put
View Answer

Answer: d
Explanation: Put is not a System class variable. The most

6 of 7 3/19/18, 10:29 AM
Inbuilt Classes - Object Oriented Programming... about:reader?url=https://www.sanfoundry.com/...

general and basic variables are err, out and in. The
variables can handle most of the tasks performed in a
program.

15. Which package contains the utility classes?


a) java.lang
b) java.utility
c) java.util
d) java.io
View Answer

Answer: c
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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

7 of 7 3/19/18, 10:29 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

IO Class - Object Oriented


Programming Questions and
Answers
by Manish
7-8 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on “IO
Class”.

1. 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
View Answer

Answer: c
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 flexibility to make the
programs more user friendly.

2. IO class provides input and output through


______________________

1 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

a) Data streams
b) Serialization
c) File system
d) Data streams, serialization and file system
View Answer

Answer: d
Explanation: 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.

3. Which among the following class contains the methods to


access character based console device?
a) Console
b) File
c) Device
d) Pipe
View Answer

Answer: a
Explanation: 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.

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

2 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

d) An abstract which can represent a file in any format


View Answer

Answer: c
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.

5. 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
View Answer

Answer: a
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.

6. 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 only
View Answer

Answer: d
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

3 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

source are allowed to be accessed.

7. What does FilePermission class do?


a) This class is used to give permission rights to a file
b) This class is used to restrict use of permissions
c) This class is used to represent device access
permissions
d) This class is used to represent file access permissions
View Answer

Answer: d
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.

8. Which class among the following makes incorrect


assumptions?
a) LineNumberInputStream
b) LineNumberReader
c) LineReader
d) LineBuffer
View Answer

Answer: a
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.

9. Reader class is _________________


a) Used to read from files

4 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

b) Abstract class to read character streams


c) Abstract class to input character streams
d) Used to take input from standard input stream
View Answer

Answer: b
Explanation: The Reader class is an abstract class which
can be used to read characters stream. It can’t be used for
any kind of input. It can just read the existing data.

10. Which class can handle IO class interrupt?


a) ExceptionIO
b) InteruptedIO
c) InteruptedIOException
d) IOInteruptException
View Answer

Answer: c
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.

11. 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
View Answer

Answer: d
Explanation: The StringReader can only work with the string
type data. Even if a character array is given, it might

5 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

produce some errors in code. Hence only the string values


can be handled properly.

12. Which exception handler can be used when character


encoding is not supported?
a) UnsupportedException
b) UnsupportedEncodingException
c) SupportException
d) EncodingException
View Answer

Answer: b
Explanation: 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.

13. PushBackReader allows the streams to be pushed back


to the stream.
a) True
b) False
View Answer

Answer: a
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.

14. RandomAccessFile can be used to


_______________________
a) Read from a random access file

6 of 7 3/19/18, 10:30 AM
IO Class - Object Oriented Programming Questi... about:reader?url=https://www.sanfoundry.com/...

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
View Answer

Answer: c
Explanation: 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.

15. Which among the following is a serialization’s descriptor


for any class?
a) StreamClass
b) ObjectStreamClass
c) ObjectStream
d) StreamObjectClass
View Answer

Answer: b
Explanation: 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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

7 of 7 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

String Class - Object Oriented


Programming Questions and
Answers
by Manish
8-10 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on “String
Class”.

1. 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
View Answer

Answer: a
Explanation: The object of string class are mostly
immutable. This means that the String objects are constant.
These can’t be changed once created.

2. How to declare an object of class String?


a) String object_Name = value;
b) String object_name = new;
c) String object_name= new value;

1 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

d) String object_name= value new;


View Answer

Answer: a
Explanation: 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.

3. 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
View Answer

Answer: b
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.

4. 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);
View Answer

Answer: a

2 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

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.

5. 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
View Answer

Answer: c
Explanation: 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.

6. 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
View Answer

3 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

Answer: d
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.

7. 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
View Answer

Answer: c
Explanation: 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.

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 string
View Answer

Answer: a
Explanation: The function is used to get the last occurrence

4 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

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. 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
View Answer

Answer: b
Explanation: 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.

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

Answer: c
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

5 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

can use compareToIgnoreCase() function.

11. String class provides function toUpper() to


_____________________
a) Convert first character to upper case
b) Convert last character to upper case
c) Convert the whole string characters to upper case
d) Convert upper case to lower and lower to upper cases
View Answer

Answer: c
Explanation: The function is used to convert each character
of the string. If the character is already upper case then it
remains the same. But if some character is in lower case
then it will be converted to upper case.

12. 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
View Answer

Answer: d
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 end of string.

13. Function replace() accepts _____________ arguments.


a) 1
b) 2

6 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

c) 3
d) 4
View Answer

Answer: b
Explanation: 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.

14. 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 string
View Answer

Answer: a
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.

15. The string class deals with string of only character type.
a) True
b) False

7 of 8 3/19/18, 10:30 AM
String Class - Object Oriented Programming Qu... about:reader?url=https://www.sanfoundry.com/...

View Answer

Answer: a
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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

8 of 8 3/19/18, 10:30 AM

You might also like