WorksheetsJava
Total questions: 12
Worksheet time: 6mins
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?
Platform-specific machine code
Java bytecode class file
Native shared object file
Operating system executable binary
Which Java operator performs arithmetic right shift, preserving the sign bit for negative integers?
>>> unsigned shift operator
>> signed shift operator
<< left shift operator
^ bitwise XOR operator
For an arithmetic right shift of -1 by 4, why does the result remain -1?
Zeros fill the leftmost bits
Ones fill due to sign preservation
Bits rotate circularly on shift
Two’s complement becomes zero
Why does super.type print "Generic Vehicle" while type prints "Car" in the Car class?
Fields are always overridden at runtime
super refers to the parent class context
type is a static variable in Vehicle
Car shadows Vehicle methods only
Which statement best illustrates inheritance in Java?
Implementing multiple interfaces in a class
Creating an object using a constructor
Extending a class to reuse behavior
Overloading methods with same name
Given main reads args[0], args[1], args[2], which exception occurs if the program is launched with only one argument?
ArrayIndexOutOfBoundsException
NumberFormatException
FileNotFoundException
UnsupportedOperationException
Order the usual steps to establish a JDBC connection.
Load driver, get Connection, create Statement
Create Statement, get Connection, load driver
Get Connection, load driver, create Statement
Load driver, create Statement, get Connection
Why is PreparedStatement generally preferred over Statement for repeated queries?
It precompiles and safely binds parameters
It dynamically builds strings at runtime
It avoids network round trips entirely
It caches results on the client side
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?
count equals three for all instances
count equals one for each instance
count resets to zero after each constructor
count equals three only for the last instance
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?
Runtime polymorphism via method overriding
Compile-time polymorphism via overloading
Encapsulation through private fields
Abstraction using abstract classes only
When overriding makeSound() in Dog and Cat, which rule must be followed for valid overriding?
Same method signature as base
Different access modifier only
Different return type always
Additional checked exceptions required
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’?
View text field widget
Controller action handler
Model service or entity
Database driver library
