String Review
Classes
Arrays
Methods
Class Construction
100

What’s the result of "hello".substring(1, 4)?

"ell"

100

What is an instance variable?

A variable that belongs to an object.
private int age;

100

What is the index of the first element in a Java array?

0

100

What’s the difference between a void and a non-void method?

A void method performs an action but doesn’t return a value; non-void methods return something.

100

What keyword is used to create a new object from a class?

new

200

Why can’t you modify a String after creating it?

Strings are immutable. Methods like .concat() make new Strings.

200

What’s a class variable (static variable)?

A variable shared by all objects of a class.
static int count;

200

What happens if you try to access arr[arr.length]?

ArrayIndexOutOfBoundsException

200

What happens if two methods have the same name but different parameters?

They are overloaded — Java chooses the one matching the argument list.

200

What is the default value of an uninitialized boolean instance variable?

false

300

How do you compare two Strings for equality?

Use .equals() instead of ==.

300

Why make instance variables private?

To protect them from direct modification (data integrity).

300

How can you check if two arrays have the same elements in the same order?

Arrays.equals(a, b)
Can't use a==b

or loop through to see if each element is the same

300

What does the return statement do?

Sends a value back to the caller and ends the method.

300

What’s the purpose of the this keyword?

(ex. this.name = name)

The current object (the instance that called the method)?

400

What’s the output of "banana".indexOf("na", 3)?

4 (search starts at index 3).

400

What’s the difference between a class and an object?

A class is a blueprint or template; an object is an instance created from that blueprint.

400

What’s wrong with int[] a = new int[-3];?

Array length can’t be negative, causes NegativeArraySizeException.

400

What’s the difference between a parameter and an argument?

Parameters are variables in the method definition; arguments are actual values passed in when calling it.

400

When calling a constructor that has parameters, what must you provide?

The correct number and types of arguments.

500

What is the result of:

university.substring(2, 7).indexOf('s')


3

500

What happens if you don’t write a constructor in a class?

Java provides a default constructor that takes no parameters and sets all variables to default values (0, false, or null).

500

How do you loop through an array with an enhanced for loop?

for (int element : values){}

500

Why can two methods with the same name in different classes behave differently?

Because of method overriding — subclasses redefine inherited methods with new behavior.

500

Why can’t instance variables be accessed directly from a static method?

Static methods belong to the class, not an instance, instance variables only exist in specific objects.