NEW
Font size
WorksheetsJava Packages
Total questions: 50
Worksheet time: 25mins
Which keyword is used to define a package in Java?
import
package
extends
implements
What is the default package that is automatically available to every Java program?
java.io
java.lang
java.util
java.sql
Which statement correctly imports all classes from the java.util package?
import java.util.*;
include java.util.*;
use java.util.*;
import all java.util;
Packages in Java primarily help with which of the following?
Memory allocation
Code reusability
Namespace management
Compilation speed
A fully qualified class name consists of which components?
Only class name
Package name + class name
Import statement
None of these
Can two classes with the same name exist in different packages?
Yes
No
What is the correct syntax to refer to a class from another package without an import when creating an object?
package.className
import package.className;
package::className
Use the fully qualified name package.className
Which package is automatically imported in every Java program?
java.io
java.lang
java.util
java.sql
What is the hierarchy of packages called in Java?
Module tree
Package chain
Namespace
Package hierarchy
Wrapper classes are primarily used to:
Convert objects to primitives
Convert primitives to objects
Perform file I/O
Handle exceptions
Which of these is not a Java wrapper class?
Integer
Float
Character
String
Which method converts a string to an int primitive in Java?
Integer.toString()
Integer.valueOf()
Integer.parseInt()
parseInteger()
What is autoboxing in Java?
Converting wrapper to primitive
Converting primitive to wrapper
Automatic error handling
None of these
What is unboxing in Java?
Converting wrapper to primitive
Converting primitive to wrapper
Parsing strings to numbers
Automatically importing packages
Which statement about the Double wrapper class is true?
Immutable
Mutable
Implements Runnable
Package-private
Boolean.valueOf("true") returns:
true
false
Which Integer class method returns the primitive int value contained in the wrapper?
intValue()
getInt()
parse()
valueOf()
The direct superclass of all Java wrapper classes is:
Object
Number
Wrapper
None
Wrapper classes are located in which package by default?
java.util
java.lang
java.io
java.wrapper
Lambda expressions were introduced in which Java version?
Java 6
Java 7
Java 8
Java 9
A lambda expression in Java can be used with:
Abstract class
Functional interface
Annotation type
Package
Which description best matches unboxing?
Automatic conversion of Integer to int
Automatic conversion of int to Integer
Manual parsing using Integer.parseInt
Casting Object to Integer
Which type is specifically intended to be used with lambda expressions in Java?
Abstract class
Functional interface
Concrete class
Any class
What is a functional interface?
Interface with one method
Interface with any number of methods
Choose the correct syntax pattern for a Java lambda expression.
(parameters) -> expression
-> parameters expression
(parameters) <- expression
None
Which package contains core functional interfaces in Java?
java.lang
java.util.function
java.io
java.lambda
Lambda expressions can access which kind of local variables?
Only static variables
Final or effectively final local variables
Global variables only
None
Which of the following is a correct example of a lambda?
x -> x*x
(x) <- x*x
(x,y) => x+y
None
A lambda expression can replace what common Java construct?
Anonymous inner class
Package declaration
Interface
None
The return type of a lambda is inferred by which component?
Compiler
JVM
Programmer
Which Java keyword is used to declare an interface?
class
extends
interface
package
Can a Java interface have variables?
Yes, they are public static final by default
No
Can a Java interface have constructors?
Yes
No
Which keyword is used by a class to implement an interface?
extends
implements
include
import
Can an interface extend another interface?
Yes
No
Can an interface extend a class?
Yes
No
From Java 8 onward, interfaces can contain which kinds of methods?
Only abstract methods
Default and static methods
Constructors
In Java, multiple inheritance of type is achieved through:
Classes
Interfaces
When a class implements an interface, which method type must the class provide implementations for?
Default methods
Abstract methods
Static methods
What is the access modifier of interface methods by default?
public
private
protected
Which keyword is used to handle exceptions in Java?
try
catch
throw
All of these
In Java, the parent class of all exceptions is:
Error
Throwable
Exception
Which block in a try-catch-finally structure is always executed?
try
catch
finally
throw
Checked exceptions are checked at:
Compile time
Runtime
Unchecked exceptions are subclasses of:
RuntimeException
IOException
Throwable
What happens if no catch block matches a thrown exception?
Program terminates abnormally
Program continues
Which keyword is used to throw an exception manually in Java?
throws
throw
try
catch
Can a try block exist without a catch block?
Yes, if followed by finally
No
Which of the following best describes a user-defined exception?
Exception defined by programmer
JVM defined
Which method prints a description of an exception?
print()
printStackTrace()
getMessage()
Both B and C
