WorksheetsJava Arrays and Inheritance Quiz
Total questions: 15
Worksheet time: 23mins
How do you declare and initialize an integer array with values 10, 20, 30 in a single statement?
int[] arr = new int[3]{10, 20, 30};
int arr[] = {10, 20, 30};
int arr[] = new int{10, 20, 30};
int arr[] = new int[3]; arr = {10, 20, 30};
Which of the following correctly describes how arrays are stored in Java memory?
Array elements are stored on the stack sequentially
Array object and elements are stored in heap memory contiguously
Array elements are scattered randomly in heap memory
Arrays are stored in static memory
What happens when you access an invalid index of an array?
Compilation error
ArrayIndexOutOfBoundsException at runtime
Returns null
Returns default value
What is a jagged array in Java?
3D array with equal size in all dimensions
An array with rows having varying lengths
A 2D array with fixed rows and columns
An array with negative indices
What is the direct superclass of every Java class if no other superclass is specified?
Class
Object
String
Super
Which of the following keywords prevents a class from being subclassed?
final
static
private
abstract
Java supports multiple inheritance through:
Classes
Interfaces
Both classes and interfaces
None of the above
What is method overriding?
Defining a method with the same name and signature in subclass to replace superclass method
Defining two methods with the same name but different parameters in a class
Defining a method only in the superclass
Calling superclass method from subclass
What is the use of the super keyword in inheritance?
Call superclass constructor or method
Declare a subclass
Call a static method
None of the above
Which access modifier allows a superclass method to be inherited but only accessible in subclasses and within the package?
private
public
protected
default (package-private)
What is dynamic method dispatch?
Binding method calls at compile time
Binding method calls at runtime based on object type
Binding static methods at runtime
Calling superclass methods from subclass
Which class keyword allows a class to have abstract methods but cannot be instantiated?
final
abstract
interface
static
Which of the following statements is true about interfaces?
Interfaces can contain implemented methods (default and static methods)
Interfaces cannot have method declarations
A class can implement only one interface
Interfaces cannot extend other interfaces
If a subclass overrides a method, how can it call the original method of the superclass?
Using this.methodName()
Using super.methodName()
Using parent.methodName()
It is not possible to call superclass method
What is multilevel inheritance?
A class inherits from multiple classes
A class inherits from a superclass, which itself inherits from another superclass
A class inherits from multiple interfaces
Multiple classes inherit from the same superclass
