Java Practice Quiz on Exception Handling

Java Practice Quiz on Exception Handling

University

13 Qs

quiz-placeholder

Similar activities

PHP - Syntax & Output

PHP - Syntax & Output

University

15 Qs

BOOLEAN CLUB QUIZ 1

BOOLEAN CLUB QUIZ 1

University

10 Qs

HTML Quiz

HTML Quiz

University

10 Qs

2023-2024 OA5 Quiz 1

2023-2024 OA5 Quiz 1

University

10 Qs

[Generation Girl] - Day 1 (Post Test)

[Generation Girl] - Day 1 (Post Test)

6th Grade - University

15 Qs

Web Dev Midterm Quiz

Web Dev Midterm Quiz

University

15 Qs

Third Year Placement Training Revision Test

Third Year Placement Training Revision Test

University

10 Qs

PRUEBA FINAL COMPUTACION

PRUEBA FINAL COMPUTACION

1st Grade - University

18 Qs

Java Practice Quiz on Exception Handling

Java Practice Quiz on Exception Handling

Assessment

Quiz

Computers

University

Practice Problem

Medium

Created by

Achin Jain

Used 29+ times

FREE Resource

AI

Enhance your content in a minute

Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...

13 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

The built-in base class in Java, which is used to handle all exceptions is:

Raise

Exception

Error

Throwable

2.

MULTIPLE CHOICE QUESTION

2 mins • 1 pt

Which of these is a super class of all errors and exceptions in the Java language?

RunTimeExceptions

Throwable

Catchable

None

3.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Predict the output of following Java program

class Main

{

public static void main(String args[])

{

try

{

throw 10;

}

catch(int e)

{

System.out.println("Got the Exception " + e);

}

}

}

Got the Exception 10

Got the Exception 0

Compiler Error

4.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

class Test extends Exception { }

class Main {

public static void main(String args[]) {

try {

throw new Test();

}

catch(Test t) {

System.out.println("Got the Test Exception");

}

finally {

System.out.println("Inside finally block ");

}

}

}

Got the Test Exception

Inside finally block

Got the Test Exception

Inside finally block

Compiler Error

5.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Output of following Java program?

class Main {

public static void main(String args[]) {

int x = 0;

int y = 10;

int z = y/x;

}

}

Compiler Error

Compiles and runs fine

Compiles fine but throws ArithmeticException exception

6.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

class Base extends Exception {}

class Derived extends Base {}

public class Main {

public static void main(String args[]) {

// some other stuff

try {

// Some monitored code

throw new Derived();

}

catch(Base b) {

System.out.println("Caught base class exception");

}

catch(Derived d) {

System.out.println("Caught derived class exception");

}

}

}

Caught base class exception

Caught derived class exception

Compiler Error because derived is not throwable

Compiler Error because base class exception is caught before derived class

7.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

class Test

{

public static void main (String[] args)

{

try

{

int a = 0;

System.out.println ("a = " + a);

int b = 20 / a;

System.out.println ("b = " + b);

}

catch(ArithmeticException e)

{

System.out.println ("Divide by zero error");

}

finally

{

System.out.println ("inside the finally block");

}

}

}

Compile error

Divide by zero error

a = 0

Divide by zero error

inside the finally block

a = 0

inside the finally block

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?

Discover more resources for Computers