GoConqr has a new look! Let us know what you think.

Quiz

04-Objectives-Wise-Handling

Wong Fei Hung 40 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (40)

  1. 1Which ofthese statements are true?
    1. AIfa RuntimeException is not caught, the method will terminate and normal
      execution ofthe thread will resume.
    2. BAn overriding method must declare that it throws the same exception classes as the
      method it overrides
    3. CThe main method ofa program can declare that it throws checked exceptions.
    4. DA method declaring that it throws a certain exception class may throw instances of
      any subclass ofthat exception class
    5. Efinally blocks are executed ifand only ifan exception gets thrown while inside the
      corresponding try block
  2. 2Assume that a method named 'method1' contains code which may raise a non-runtime
    (checked) Exception.
    What is the correct way to declare that method so that it indicates that it expects the
    caller to handle that exception?
    1. Apublic void method1( ) throws Throwable
    2. Bpublic void method1( ) throw Exception
    3. Cpublic void method1( ) throw new Exception
    4. Dpublic void method1( ) throws Exception
    5. Epublic void method1( )
  3. 3Which ofthe following can be thrown using a throw statement?
    1. AEvent
    2. BObject
    3. CThrowable
    4. DException
    5. ERuntimeException
  4. 4What will be the result ofcompiling and running the following program ?
    class NewException extends Exception { }
    class AnotherException extends Exception { }
    public class ExceptionTest{
    public static void main( String [ ] args) throws Exception{
    try{
    m2( ) ;
    }f
    inally{ m3( ) ; }
    }p
    ublic static void m2( ) throws NewException{ throw new NewException( ) ; }
    public static void m3( ) throws AnotherException{ throw new AnotherException( ) ; }
    }
    1. AIt will compile but will throw AnotherException when run.
    2. BIt will compile but will throw NewException when run.
    3. CIt will compile and run without throwing any exceptions.
    4. DIt will not compile.
    5. ENone ofthe above.
  5. 5What will be the result ofcompiling and running the following program ?
    class NewException extends Exception { }
    class AnotherException extends Exception { }
    public class ExceptionTest{
    public static void main( String[ ] args) throws Exception{
    try{
    m2( ) ;
    }f
    inally{
    m3( ) ;
    }c
    atch ( NewException e) { }
    }p
    ublic static void m2( ) throws NewException { throw new NewException( ) ; }
    public static void m3( ) throws AnotherException{ throw new AnotherException( ) ; }
    }
    1. AIt will compile but will throw AnotherException when run.
    2. BIt will compile but will throw NewException when run.
    3. CIt will compile and run without throwing any exceptions.
    4. DIt will not compile.
    5. ENone ofthe above.
  6. 6Which ofthe following are standard Java exception classes?
    1. AFileNotFoundException
    2. BInputException
    3. CCPUError
    4. DMemoryException
    5. ESecurityException
  7. 7What will be the output when the following program is run?
    package exceptions;
    public class TestClass {
    public static void main( String[ ] args) {
    try{
    doTest( ) ;
    }c
    atch( MyException me) {
    System. out. println( me) ;
    }
    }s
    tatic void doTest( ) throws MyException{
    int[ ] array = new int[ 10] ;
    array[ 10] = 1000;
    doAnotherTest( ) ;
    }s
    tatic void doAnotherTest( ) throws MyException{
    throw new MyException( " Exception from doAnotherTest" ) ;
    }
    }c
    lass MyException extends Exception {
    public MyException( String msg) {
    super( msg) ;
    }
    }
    1. AException in thread " main"
      j ava. lang. ArrayIndexOutOfBoundsException: 10
      at exceptions. TestClass. doTest( TestClass. j ava: 24)
      at exceptions. TestClass. main( TestClass. j ava: 14)
    2. BError in thread " main" j ava. lang. ArrayIndexOutOfBoundsException
    3. Cexceptions. MyException: Exception from doAnotherTest
    4. Dexceptions. MyException: Exception from doAnotherTest
      at exceptions. TestClass. doAnotherTest( TestClass. j ava: 29)
      at exceptions. TestClass. doTest( TestClass. j ava: 25)
      at exceptions. TestClass. main( TestClass. j ava: 14)
      Expl
  8. 8What will the following code print when compiled and run?
    abstract class Calculator{
    abstract void calculate( ) ;
    public static void main( String[ ] args) {
    System. out. println( " calculating" ) ;
    Calculator x = null;
    x. calculate( ) ;
    }
    }
    1. AIt will not compile.
    2. BIt will not print anything and will throw NullPointerException
    3. CIt will print calculating and then throw NullPointerException.
    4. DIt will print calculating and will throw NoSuchMethodError
    5. EIt will print calculating and will throw MethodNotImplementedException
  9. 9A Java programmer is developing a desktop application. Which ofthe following
    exceptions would be appropriate for him to throw explicitly from his code?
    1. ANullPointerException
    2. BClassCastException
    3. CArrayIndexOutofBoundsException
    4. DException
  10. 10What will the following code print?
    public class Test{
    public int luckyNumber( int seed) {
    if( seed > 10) return seed%10;
    int x = 0;
    try{
    if( seed%2 == 0) throw new Exception( " No Even no. " ) ;
    else return x;
    }c
    atch( Exception e) {
    return 3;
    }f
    inally{
    return 7;
    }
    }
    public static void main( String args[ ] ) {
    int amount = 100, seed = 6;
    switch( new Test( ) . luckyNumber( 6) ) {
    case 3: amount = amount * 2;
    case 7: amount = amount * 2;
    case 6: amount = amount + amount;
    default :
    }
    System. out. println( amount) ;
    }
    }
    1. AIt will not compile.
    2. BIt will throw an exception at runtime.
    3. C800
    4. D200
    5. E400

Information

Description
OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Quiz on 04-Objectives-Wise-Handling, created by Wong Fei Hung on 01/08/2017.
Language
Português
Views
0
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?