Search Header Logo

OOPJ Quiz

Authored by GAUTAMI UPPADA

Other

University

Used 2+ times

OOPJ Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

In the context of encapsulation, what is the primary purpose of using private instance variables with public getter and setter methods in a Java class?

To allow unrestricted access to the class’s internal data

To ensure that the class can only be instantiated within the same package

To hide the internal state of the object and provide controlled access to it

To enable automatic memory management by the JVM

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

When a Java program is compiled, the JVM generates bytecode. What happens if a .class file is executed on a machine with a different architecture than the one it was compiled on?

The program will fail to execute due to architecture mismatch

The JVM interprets the bytecode, making it platform-independent

The bytecode is recompiled into native code specific to the new architecture

The JRE throws a ClassFormatError at runtime

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Consider a class with a static initialization block that initializes a static array. If an exception occurs in the static block during class loading, what will happen?

The exception is caught automatically by the JVM, and the class is loaded

The class loading fails, and a ExceptionInInitializerError is thrown

The static block is skipped, and the array remains uninitialized

The program continues execution but skips the static array initialization

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

In a multilevel inheritance hierarchy, a subclass overrides a method from its parent class. If the parent class method is declared with the final keyword, what is the outcome?

The method can be overridden only if the subclass is in the same package

Correct Answer: B

The method is overridden, but the final keyword is ignored in the subclass

The subclass can override the method, but it must also mark it as final

The subclass cannot override the method, and a compile-time error occurs

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

A Java interface defines a default method, and a class implementing this interface provides its own implementation of the same method. Which implementation is invoked when the method is called on an instance of the class?

The interface’s default method is always invoked

The method invocation depends on the access modifier of the class’s method

The class’s implementation overrides the default method

A runtime exception is thrown due to method conflict

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

In a try-catch block, a finally block contains a return statement. If both the try block and the catch block also contain return statements, which return value takes precedence?

The return value from the finally block

The return value from the try block

The return value from the catch block

A NullPointerException is thrown

7.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

When using a StringBuilder to modify a string, what happens to the original string if the StringBuilder was initialized with a String object?

The original String object is modified in the string pool

The StringBuilder modifies the string pool, causing a runtime error

The original String is garbage collected immediately

The original String remains unchanged, and StringBuilder operates on a separate copy

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?