
IT Interview Exam Questions: JAVA 12 (IT Campus Placement)
Subject: JAVA 12
Part 12: List for questions and answers of JAVA
Q1. The exception class is in ____ package
a) java.file
b) java.io
c) java.lang
d) java.util
Q2. Which keyword is used to monitor statement for exception?
a) try
b) catch
c) throw
d) throws
Q3. If an exception is generated in try block , then it is caught in ____ block
a) finally
b) throw
c) throws
d) catch
Q4. To explicitly throw an exception , ______ keyword is used
a) try
b) catch
c) throw
d) throwing
Q5. ______ is a superclass of all exception classes.
a) Exception
b) Throwable
c) RuntimeException
d) IOException
Q6. Exception is subclass of ____ class.
a) Exception
b) Throwable
c) RuntimeException
d) IOException
Q7. If a statement tries to divide by zero which exception is thrown?
a) ArithemticException
b) NullPointerException
c) NumberFormatException
d) None of these
Q8. When a method can throw an exception then it is specified by _____ keyword
a) finally
b) throw
c) throws
d) catch
Q9. Which block gets executed compulsory whether exception is caught or not
a) finally
b) throw
c) throws
d) catch
Q10. To create our own exception class , we have to _______
a) Extend exception class
b) Create our own try and catch block
c) use finally block
d) Use throws keyword
Q11. In case of multiple catch blocks,______
a) The superclass exception must be caught first
b) The superclass exception can not caught first
c) Either super or subclass can be caught first
d) None of these
Q12. When an array element is accessed beyond the array size , ____ exception is thrown
a) ArrayElementOutOfLimit
b) ArrayIndexOutOfBounds Exception
c) ArrayIndexOutOfBounds
d) ArrayElementOutOfBounds
Q13. Which method is used to print the description of the exception?
a) printStackTrace()
b) printExceptionMessage()
c) printStackMessage()
d) printExceptionTrace()
Q14. Which of the following must be true of the object thrown by a throw statement?
a) It must be assignable to the Throwable type
b) It must be assignable to the Error type
c) It must be assignable to the Exception type
d) It must be assignable to the String type
Q15. parseInt() and parseLong() method throws ________________ ?
a) ArithmeticException
b) ClassNotFoundException
c) NullPointerException
d) NumberFormatException
Q16. exception is in java
a) abnormal condition
b) compile time error
c) normal flow of control
d) Runtime error
Q17. what is checked exception
a) Error
b) Runtime Erroe
c) SQL Exception
d) None of these
Q18. What will be the output of the program?
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( “Finally” );
}
}
}
a) Finally
b) Compilation fails
c) The code runs with no output
d) An exception is thrown at runtime
Q19. What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println(“Exception”);
}
catch (ArithmeticException ae)
{
System.out.println(” Arithmetic Exception”);
}
System.out.println(“finished”);
a) finished
b) Exception
c) Compilation fails
d) Arithmetic Exception
Q20. What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print(“A”);
}
catch (Exception ex)
{
System.out.print(“B”);
}
finally
{
System.out.print(“C”);
}
System.out.print(“D”);
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
a) ABCD
b) Compilation fails
c) C is printed before exiting with an error message
d) BC is printed before exiting with an error message
Part 12: List for questions and answers of JAVA
Q1. Answer: c
Q2. Answer: a
Q3. Answer: c
Q4. Answer: c
Q5. Answer: b
Q6. Answer: b
Q7. Answer: a
Q8. Answer: c
Q9. Answer: a
Q10. Answer: a
Q11. Answer: b
Q12. Answer: b
Q13. Answer: a
Q14. Answer: a
Q15. Answer: d
Q16. Answer: a
Q17. Answer: c
Q18. Answer: a
Q19. Answer: c
Q20. Answer: d