Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

You compile MyApp.java on Windows into MyApp.class, copy the same class file to Linux and macOS, and it runs on both without recompilation. What compiled file format enables this portability?

a)

Platform-specific machine code

b)

Java bytecode class file

c)

Native shared object file

d)

Operating system executable binary

2.

Which Java operator performs arithmetic right shift, preserving the sign bit for negative integers?

a)

>>> unsigned shift operator

b)

>> signed shift operator

c)

<< left shift operator

d)

^ bitwise XOR operator

3.

For an arithmetic right shift of -1 by 4, why does the result remain -1?

a)

Zeros fill the leftmost bits

b)

Ones fill due to sign preservation

c)

Bits rotate circularly on shift

d)

Two’s complement becomes zero

4.

Why does super.type print "Generic Vehicle" while type prints "Car" in the Car class?

a)

Fields are always overridden at runtime

b)

super refers to the parent class context

c)

type is a static variable in Vehicle

d)

Car shadows Vehicle methods only

5.

Which statement best illustrates inheritance in Java?

a)

Implementing multiple interfaces in a class

b)

Creating an object using a constructor

c)

Extending a class to reuse behavior

d)

Overloading methods with same name

6.

Given main reads args[0], args[1], args[2], which exception occurs if the program is launched with only one argument?

a)

ArrayIndexOutOfBoundsException

b)

NumberFormatException

c)

FileNotFoundException

d)

UnsupportedOperationException

7.

Order the usual steps to establish a JDBC connection.

a)

Load driver, get Connection, create Statement

b)

Create Statement, get Connection, load driver

c)

Get Connection, load driver, create Statement

d)

Load driver, create Statement, get Connection

8.

Why is PreparedStatement generally preferred over Statement for repeated queries?

a)

It precompiles and safely binds parameters

b)

It dynamically builds strings at runtime

c)

It avoids network round trips entirely

d)

It caches results on the client side

9.

In a Counter class where a static variable count is incremented in the constructor, what is the correct behavior after creating three objects in main?

a)

count equals three for all instances

b)

count equals one for each instance

c)

count resets to zero after each constructor

d)

count equals three only for the last instance

10.

A base class Animal defines makeSound(). Dog and Cat override makeSound() to print specific strings. What concept is demonstrated when calling makeSound() on Dog and Cat references at runtime?

a)

Runtime polymorphism via method overriding

b)

Compile-time polymorphism via overloading

c)

Encapsulation through private fields

d)

Abstraction using abstract classes only

11.

When overriding makeSound() in Dog and Cat, which rule must be followed for valid overriding?

a)

Same method signature as base

b)

Different access modifier only

c)

Different return type always

d)

Additional checked exceptions required

12.

Neha is developing a web application where users can register their names. Before saving the name to the database, which MVC component should own the validation of the ‘name’?

a)

View text field widget

b)

Controller action handler

c)

Model service or entity

d)

Database driver library