OOPJ Quiz

OOPJ Quiz

University

10 Qs

quiz-placeholder

Similar activities

Java set 1

Java set 1

University

10 Qs

Hard minecraft questions

Hard minecraft questions

4th Grade - Professional Development

10 Qs

Java Variables and Control Structures lec2

Java Variables and Control Structures lec2

University

10 Qs

Java Set 2

Java Set 2

University

10 Qs

java questions

java questions

University

10 Qs

String Methods Review

String Methods Review

9th Grade - University

10 Qs

JAVA FUNDAMENTALS

JAVA FUNDAMENTALS

University

12 Qs

JSP

JSP

University

10 Qs

OOPJ Quiz

OOPJ Quiz

Assessment

Quiz

Other

University

Easy

Created by

GAUTAMI UPPADA

Used 2+ times

FREE Resource

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

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?