wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

P1_APLab2Quiz_B3B4

Total questions: 10

Worksheet time: 4mins

Name
Class
Date
1.

What is the primary purpose of abstract methods in Java?

a)

To create methods that can only be accessed within the same package.

b)

To prevent the instantiation of abstract classes.

c)

To define methods that must be implemented by any concrete class derived from the abstract class.

d)

To provide default implementations for methods in derived classes.

2.

In Java, if an exception is thrown in a try block and there are multiple catch blocks, what happens if the exception type does not exactly match any catch block but is a subclass of one of the catch block's parameters?

a)

The compiler throws an error because of ambiguity.

b)

The catch block with the superclass parameter will be executed.

c)

The catch block with the subclass parameter will be executed.

d)

The program will terminate without handling the exception.

3.

Which of the following statements about checked and unchecked exceptions in Java is correct?

a)

Checked exceptions must be caught or declared in the method signature using throws keyword.

b)

Unchecked exceptions are always caught by the compiler.

c)

Checked exceptions are subclasses of RuntimeException.

d)

Unchecked exceptions must be caught using try-catch blocks.

4.

Which statement is false regarding abstract classes in Java?

a)

Abstract classes can have abstract methods with or without method bodies.

b)

Abstract classes can be declared as final to prevent further inheritance.

c)

Abstract classes cannot be instantiated directly; they need to be subclassed.

d)

Abstract classes can have constructors for initializing instance variables.

5.

Predict the output.

a)

A C

b)

A B C

c)

B C

d)

B

6.

What happens if a method uses throws but does not throw any exception?

a)

It will cause a compilation error.

b)

It will throw a runtime exception.

c)

It will throw a checked exception automatically.

d)

It will not cause any issue.

7.

In Java, why can't methods in interfaces have access modifiers other than public?

a)

It violates the encapsulation principle.

b)

Interfaces are always public, so their methods are implicitly public.

c)

It leads to ambiguity in method visibility.

d)

Methods in interfaces can have different access modifiers based on the implementing class.

8.

Which of the following situations is best represented by a checked exception in Java?

a)

The program runs out of memory due to a logic error.

b)

The program encounters a divide-by-zero operation.

c)

The program attempts to open a file that does not exist.

d)

The program enters an infinite loop due to a coding mistake.

9.

Which statement is false regarding interfaces in Java?

a)

Interfaces can have method declarations without method bodies.

b)

A class can implement multiple interfaces in Java.

c)

Interfaces can contain instance variables that can have default values.

d)

Interfaces can have constructors for initializing instance variables.

10.

Which of the following statements is false regarding exceptions and errors in Java?

a)

Exceptions are events that occur during the execution of a program that disrupts the normal flow of instructions.

b)

Errors are typically ignored in Java programs as they are part of the normal execution flow.

c)

Exceptions can be caught and handled using try-catch blocks.

d)

Errors are typically not recoverable situations, and programs should not catch errors.