wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Arrays and Inheritance Quiz

Total questions: 15

Worksheet time: 23mins

Name
Class
Date
1.

How do you declare and initialize an integer array with values 10, 20, 30 in a single statement?

a)

int[] arr = new int[3]{10, 20, 30};

b)

int arr[] = {10, 20, 30};

c)

int arr[] = new int{10, 20, 30};

d)

int arr[] = new int[3]; arr = {10, 20, 30};

2.

Which of the following correctly describes how arrays are stored in Java memory?

a)

Array elements are stored on the stack sequentially

b)

Array object and elements are stored in heap memory contiguously

c)

Array elements are scattered randomly in heap memory

d)

Arrays are stored in static memory

3.

What happens when you access an invalid index of an array?

a)

Compilation error

b)

ArrayIndexOutOfBoundsException at runtime

c)

Returns null

d)

Returns default value

4.

What is a jagged array in Java?

a)

3D array with equal size in all dimensions

b)

An array with rows having varying lengths

c)

A 2D array with fixed rows and columns

d)

An array with negative indices

5.

What is the direct superclass of every Java class if no other superclass is specified?

a)

Class

b)

Object

c)

String

d)

Super

6.

Which of the following keywords prevents a class from being subclassed?

a)

final

b)

static

c)

private

d)

abstract

7.

Java supports multiple inheritance through:

a)

Classes

b)

Interfaces

c)

Both classes and interfaces

d)

None of the above

8.

What is method overriding?

a)

Defining a method with the same name and signature in subclass to replace superclass method

b)

Defining two methods with the same name but different parameters in a class

c)

Defining a method only in the superclass

d)

Calling superclass method from subclass

9.

What is the use of the super keyword in inheritance?

a)

Call superclass constructor or method

b)

Declare a subclass

c)

Call a static method

d)

None of the above

10.

Which access modifier allows a superclass method to be inherited but only accessible in subclasses and within the package?

a)

private

b)

public

c)

protected

d)

default (package-private)

11.

What is dynamic method dispatch?

a)

Binding method calls at compile time

b)

Binding method calls at runtime based on object type

c)

Binding static methods at runtime

d)

Calling superclass methods from subclass

12.

Which class keyword allows a class to have abstract methods but cannot be instantiated?

a)

final

b)

abstract

c)

interface

d)

static

13.

Which of the following statements is true about interfaces?

a)

Interfaces can contain implemented methods (default and static methods)

b)

Interfaces cannot have method declarations

c)

A class can implement only one interface

d)

Interfaces cannot extend other interfaces

14.

If a subclass overrides a method, how can it call the original method of the superclass?

a)

Using this.methodName()

b)

Using super.methodName()

c)

Using parent.methodName()

d)

It is not possible to call superclass method

15.

What is multilevel inheritance?

a)

A class inherits from multiple classes

b)

A class inherits from a superclass, which itself inherits from another superclass

c)

A class inherits from multiple interfaces

d)

Multiple classes inherit from the same superclass