Java
Pages
Home
Java
Interview
Monday, 21 December 2015
Exceptions Java - MCQ set 1 (25 questions, 50 marks)
Exceptions Java - MCQ set 1 (25 questions, 50 marks)
Q1 - Q5, 5 EASY level difficulty questions 1 mark each. 1 * 5 = 5 marks
Exception is a class/interface/abstract class/other?
a.
Class
b.
Interface
c.
Abstract class
d.
Other
Exception is found in which package in java
a.
java.lang
b.
java.util
c.
java.io
d.
java
Exception was introduced in which java version
a.
Java 1
b.
Java 2
c.
Java 3
d.
Java 4
Which of these class is highest in hierarchy in java
a.
java.lang.Exception
b.
java.lang.Error
c.
java.lang.Throwable
d.
java.lang.Object
What keyword is used to explicitly raise a exception?
a.
catch
b.
throw
c.
throws
d.
raise
Q6 - Q20, 15 MEDIUM level difficulty questions 2 mark each. 2 * 15 = 30 marks
What block is always executed, independently of a exception being raised?
a.
throws
b.
finally
c.
catch
d.
throw
Exception and Error are direct subclasses of?
a.
BaseException
b.
Throwable
c.
Object
d.
RuntimeException
FileNotFoundException
a.
Is a subclass/extends IOException
b.
Is a Compile time exception
c.
Found in java.io package
d.
All
IOException
a.
Found in java.io package
b.
Is a Compile time exception
c.
Is a subclass/extends Exception
d.
All
Which of these are java.lang.Error in exception handling in java
a.
VirtualMachineError
b.
IOError
c.
AssertionError
d.
ThreadDeath
e.
All
In which condition will the finally block will not be executed?
a.
When some Error occurs
b.
When Exception is raised
c.
When System.Exit(1) is called
d.
In all the cases
What type of Exceptions can be ignored at compile time?
a.
Runtime
b.
Checked
c.
Both
d.
None
What will be output of following exception handling code in java -
a.
ade
b.
adb
c.
bcde
d.
adbe
What will be output of following program -
a.
runtime exception
b.
program will compile
c.
program won't compile
d.
What will happen in this program -
a.
StackFlowoverError
b.
compile timeError
c.
StackOverflowException
d.
StackOverflowError
What is invalid statements for automatic resource management in java?
a.
Allows us to catch more than one exception in one catch block
b.
We could separate different exceptions using pipe ( | )
c.
Increases developer efforts of writing multiple catch blocks.
d.
None
multiple catch syntax was introduced in ?
a.
java 5
b.
java 6
c.
java 7
d.
java 8
Which of these points will be valid If superclass method does not throw any exception
a.
overridden method of subclass can throw any RuntimeException
b.
overridden method of subclass cannot throw any checked exception
c.
overridden method of subclass may not throw any exception.
d.
All
What will happen when catch and finally block both return value?
a.
method will return value returned by finally block
b.
method will return value returned by catch block
c.
finally block won't execute
d.
None
can a method be overloaded on basis of exceptions ?
a.
Will produce runtime error
b.
Will produce compilation error - ambiguity error
c.
Yes a method be overloaded on basis of exceptions.
d.
None
Q21 - Q25, 5 HARD level difficulty questions 3 mark each. 3 * 5 = 15 marks
What will be output of following program -
a.
runtime exception
b.
method return -> finally
c.
method return -> catch
d.
compile timeError
What will be output of following program -
a.
abc
b.
abcd
c.
runtime exception
d.
compile timeError
Which is valid about java.lang.Exceptions?
a.
The class Exception and all its subclasses that are not also subclasses of RuntimeException are checked exceptions
b.
The class Error and all its subclasses are unchecked exceptions
c.
The class RuntimeException and all its subclasses are unchecked exceptions
d.
All
What is disadvantage/invalid about try-with-resource
a.
introduced in java 7
b.
we need not to write explicit code for closing file
c.
Using multiple resources inside Try-with-resources is also allowed
d.
None
FileInputStream implements which interface for closing file automatically in java7?
a.
java.lang.AutoClose
b.
java.lang.CloseAutomatically
c.
java.lang.AutoCloseable
d.
java.lang.Closeable
Quiz 1 - Correct answers
EASY
1) a
2) a
3) a
4) d
5) b
MEDIUM
6) b
7) b
8) d
9) d
10) e
11) c
12) a
13) b
14) c
15) d
16) c
17) c
18) d
19) a
20) c
HARD
21) b
22) c
23) d
24) d
25) c
Go to TOP of the page
Exceptions Java - MCQ set 2 (25 questions, 50 marks)
Q1 - Q5, 5 EASY level difficulty questions 1 mark each. 1 * 5 = 5 marks
What type of Exceptions can NOT be ignored at compile time?
a.
Checked Exceptions
b.
Unchecked Exceptions
c.
Uncompiled Exceptions
d.
Error
java.lang.NullPointerException is a
a.
Error
b.
runtime exception
c.
Compile time exception
d.
None
What will be output of following program -
a.
compile timeError
b.
UserDefinedException will be thrown
c.
UserDefinedException will be thrown and end will be present in output
d.
None
Which of these is valid
code snippet
in exception handling in java?
a.
catch{ }
b.
finally{ }
c.
try{ }finally{ }
d.
try{ }
Which of these will be invalid declaration
a.
try-catch block.
b.
c.
try-catch-finally block.
d.
catch-finally block.
Q6 - Q20, 15 MEDIUM level difficulty questions 2 mark each. 2 * 15 = 30 marks
What will be output of following program -
a.
runtime exception
b.
compilation error
c.
superClass method
d.
SubClass method
What will be output of following exception handling code in java -
a.
SubClass method
b.
compilation error
c.
runtime exception
d.
superClass method
What will be output of following exception handling program -
a.
after calling m()
b.
runtime exception
c.
program won't compile
d.
None
What will be output of following exception handling code in java -
a.
superClass method
b.
runtime exception
c.
compilation error
d.
SubClass method
What will be output of following exception handling program -
a.
superClass method
b.
runtime exception
c.
SubClass method
d.
compilation error
What will be output of following exception handling code in java -
a.
superClass method
b.
SubClass method
c.
runtime exception
d.
None of these
If superclass method throws unchecked exception then overridden method of subclass can throw
a.
Only subclasses of exception thrown by superclass method
b.
Can't throw any exception
c.
Any checked exception
d.
Any runtime exception
What will be output of following program -
a.
runtime exception
b.
superClass method
c.
compilation error
d.
SubClass method
If superclass method throws checked exception than
a.
overridden method of subclass can declare any RuntimeException
b.
overridden method of subclass can declare narrower checked exception
c.
overridden method of subclass cannot throw broader checked exception
d.
All
Which of these is not a one of the exception handling keyword?
a.
finally
b.
exception
c.
try
d.
catch
e.
throw
What is invalid about java.lang.Error in java?
a.
Errors are abnormal conditions in application
b.
Error indicates some serious problems that our application should not try to catch
c.
Error is unchecked Exception
d.
Error is a subclass of Throwable
Which of these not a Error?
a.
VirtualMachineError
b.
ClassNotFoundError
c.
OutOfMemoryError
d.
IOError
Which is invalid about throws in Exception handling in java?
a.
throws can propagate exception to calling method
b.
throws can be used to throw multiple exception at time.
c.
throws is used inside method to throw exception
d.
None of these
What is true about exception handling keyword throw in java
a.
throw is a keyword
b.
throw can be used to throw only one exception at time.
c.
throw is used inside method
d.
All
Automatic resource management was introduced in which java version?
a.
java 5
b.
java 6
c.
java 7
d.
java 8
Q21 - Q25, 5 HARD level difficulty questions 3 mark each. 3 * 5 = 15 marks
Which of these is not a good exception handling practice?
a.
Throw exceptions when the method cannot handle the exception, and more importantly, must be handled by the caller
b.
log the exception and bubble it
c.
Bubble the exception if the method cannot handle it.
d.
Throw the exception right away
Which are valid statements in Exception handling in java?
a.
Java exception handling allows us to use multiple catch block.
b.
Exception class handled in starting catch block must be subclass of Exception class handled in following catch blocks
c.
Either one of the multiple catch block will handle exception at time
d.
All
Which is invalid statement in Exception handling in java?
a.
finally block can't throw exception
b.
try block can throw exception
c.
catch block can throw exception
d.
finally block can throw exception
Which of these exceptions are propagated automatically in java?
a.
IOException
b.
NullPointerException
c.
ClassNotFoundException
d.
SQLException
Which of these exceptions are always needed to be manually propagated?
a.
Error
b.
unchecked exceptions
c.
checked exceptions
d.
None
Quiz 2 - Correct answers
EASY
1) a
2) b
3) b
4) c
5) d
MEDIUM
6) d
7) b
8) b
9) d
10) d
11) b
12) d
13) c
14) d
15) b
16) c
17) b
18) c
19) d
20) c
HARD
21) b
22) d
23) a
24) b
25) c
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment