What is the default value of an int variable in Java?
0
How many times will a for (int i = 0; i < 5; i++) loop run?
5
How do you declare an empty array of 10 integers?
int[] arr = new int[10];
What is the correct syntax for defining a method that returns an int?
public int methodName() { }
What keyword is used to create a new object?
new
Which data type would you use to store a true/false value?
boolean
What is the difference between == and .equals() when comparing objects?
== checks the memory address, while .equals() checks the values in the object.
What is the index of the first element in an array?
0
What does the return statement do inside a method?
Ends the method and sends a value back.
What is the purpose of a constructor?
To initialize an object’s fields when it is created.
What is the result of 5/2 in Java?
2 (integer division)
What is the difference between a for loop and a while loop?
Answers vary. (Generally, a for loop is for a known number of iterations, while a while loop is for until a condition is reached)
How do you access the last element of an array named arr?
arr[arr.length - 1]
Can a method have more than one parameter?
Yup
What does this refer to inside a class?
The current object instance.
How would you declare a variable to store a single character?
char varName = 'A';
What keyword immediately stops a loop?
break
Which method adds an element to an ArrayList?
.add(element)
What is method overloading?
Defining multiple methods with the same name but different parameter lists.
How do you call a method from an object you created? (In terms of the object name)
objectName.methodName();
What is the result of: true && false || true?
true
What does the continue keyword do inside a loop?
Skips the rest of the loop and moves to the next iteration.
What happens if you try to access an array index that doesn't exist?
You get an ArrayIndexOutOfBoundsException.
What is the difference between a method’s return type and its parameters?
The return type specifies what value the method gives back after execution. Parameters are inputs passed into the method to customize its behavior.
What is the difference between a class and an object in Java?
A class is a blueprint or template that defines the structure and behavior of objects. An object is an instance of a class, created using the new keyword.