wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Packages

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

Which keyword is used to define a package in Java?

a)

import

b)

package

c)

extends

d)

implements

2.

What is the default package that is automatically available to every Java program?

a)

java.io

b)

java.lang

c)

java.util

d)

java.sql

3.

Which statement correctly imports all classes from the java.util package?

a)

import java.util.*;

b)

include java.util.*;

c)

use java.util.*;

d)

import all java.util;

4.

Packages in Java primarily help with which of the following?

a)

Memory allocation

b)

Code reusability

c)

Namespace management

d)

Compilation speed

5.

A fully qualified class name consists of which components?

a)

Only class name

b)

Package name + class name

c)

Import statement

d)

None of these

6.

Can two classes with the same name exist in different packages?

a)

Yes

b)

No

7.

What is the correct syntax to refer to a class from another package without an import when creating an object?

a)

package.className

b)

import package.className;

c)

package::className

d)

Use the fully qualified name package.className

8.

Which package is automatically imported in every Java program?

a)

java.io

b)

java.lang

c)

java.util

d)

java.sql

9.

What is the hierarchy of packages called in Java?

a)

Module tree

b)

Package chain

c)

Namespace

d)

Package hierarchy

10.

Wrapper classes are primarily used to:

a)

Convert objects to primitives

b)

Convert primitives to objects

c)

Perform file I/O

d)

Handle exceptions

11.

Which of these is not a Java wrapper class?

a)

Integer

b)

Float

c)

Character

d)

String

12.

Which method converts a string to an int primitive in Java?

a)

Integer.toString()

b)

Integer.valueOf()

c)

Integer.parseInt()

d)

parseInteger()

13.

What is autoboxing in Java?

a)

Converting wrapper to primitive

b)

Converting primitive to wrapper

c)

Automatic error handling

d)

None of these

14.

What is unboxing in Java?

a)

Converting wrapper to primitive

b)

Converting primitive to wrapper

c)

Parsing strings to numbers

d)

Automatically importing packages

15.

Which statement about the Double wrapper class is true?

a)

Immutable

b)

Mutable

c)

Implements Runnable

d)

Package-private

16.

Boolean.valueOf("true") returns:

a)

true

b)

false

17.

Which Integer class method returns the primitive int value contained in the wrapper?

a)

intValue()

b)

getInt()

c)

parse()

d)

valueOf()

18.

The direct superclass of all Java wrapper classes is:

a)

Object

b)

Number

c)

Wrapper

d)

None

19.

Wrapper classes are located in which package by default?

a)

java.util

b)

java.lang

c)

java.io

d)

java.wrapper

20.

Lambda expressions were introduced in which Java version?

a)

Java 6

b)

Java 7

c)

Java 8

d)

Java 9

21.

A lambda expression in Java can be used with:

a)

Abstract class

b)

Functional interface

c)

Annotation type

d)

Package

22.

Which description best matches unboxing?

a)

Automatic conversion of Integer to int

b)

Automatic conversion of int to Integer

c)

Manual parsing using Integer.parseInt

d)

Casting Object to Integer

23.

Which type is specifically intended to be used with lambda expressions in Java?

a)

Abstract class

b)

Functional interface

c)

Concrete class

d)

Any class

24.

What is a functional interface?

a)

Interface with one method

b)

Interface with any number of methods

25.

Choose the correct syntax pattern for a Java lambda expression.

a)

(parameters) -> expression

b)

-> parameters expression

c)

(parameters) <- expression

d)

None

26.

Which package contains core functional interfaces in Java?

a)

java.lang

b)

java.util.function

c)

java.io

d)

java.lambda

27.

Lambda expressions can access which kind of local variables?

a)

Only static variables

b)

Final or effectively final local variables

c)

Global variables only

d)

None

28.

Which of the following is a correct example of a lambda?

a)

x -> x*x

b)

(x) <- x*x

c)

(x,y) => x+y

d)

None

29.

A lambda expression can replace what common Java construct?

a)

Anonymous inner class

b)

Package declaration

c)

Interface

d)

None

30.

The return type of a lambda is inferred by which component?

a)

Compiler

b)

JVM

c)

Programmer

31.

Which Java keyword is used to declare an interface?

a)

class

b)

extends

c)

interface

d)

package

32.

Can a Java interface have variables?

a)

Yes, they are public static final by default

b)

No

33.

Can a Java interface have constructors?

a)

Yes

b)

No

34.

Which keyword is used by a class to implement an interface?

a)

extends

b)

implements

c)

include

d)

import

35.

Can an interface extend another interface?

a)

Yes

b)

No

36.

Can an interface extend a class?

a)

Yes

b)

No

37.

From Java 8 onward, interfaces can contain which kinds of methods?

a)

Only abstract methods

b)

Default and static methods

c)

Constructors

38.

In Java, multiple inheritance of type is achieved through:

a)

Classes

b)

Interfaces

39.

When a class implements an interface, which method type must the class provide implementations for?

a)

Default methods

b)

Abstract methods

c)

Static methods

40.

What is the access modifier of interface methods by default?

a)

public

b)

private

c)

protected

41.

Which keyword is used to handle exceptions in Java?

a)

try

b)

catch

c)

throw

d)

All of these

42.

In Java, the parent class of all exceptions is:

a)

Error

b)

Throwable

c)

Exception

43.

Which block in a try-catch-finally structure is always executed?

a)

try

b)

catch

c)

finally

d)

throw

44.

Checked exceptions are checked at:

a)

Compile time

b)

Runtime

45.

Unchecked exceptions are subclasses of:

a)

RuntimeException

b)

IOException

c)

Throwable

46.

What happens if no catch block matches a thrown exception?

a)

Program terminates abnormally

b)

Program continues

47.

Which keyword is used to throw an exception manually in Java?

a)

throws

b)

throw

c)

try

d)

catch

48.

Can a try block exist without a catch block?

a)

Yes, if followed by finally

b)

No

49.

Which of the following best describes a user-defined exception?

a)

Exception defined by programmer

b)

JVM defined

50.

Which method prints a description of an exception?

a)

print()

b)

printStackTrace()

c)

getMessage()

d)

Both B and C