What keyword is used to define a class?
class
What does OOP stand for?
Object-Oriented Programming
Identify the error: int x = "5";
"5" is a String, not an int
What data type is used to store a true/false value?
boolean
Name two principles of OOP
Inheritance, Encapsulation, Polymorphism, Abstraction
What’s wrong here?
if (x = 10) {
System.out.println("Ten");
}
= is assignment; should be ==
Result of this code?
int x = 5;
int y = 2;
double result = x / y;
System.out.println(result);
2.0
What’s the difference between method overloading and method overriding?
(clarify the difference)
Overloading: Same method name, different parameters (in the same class).
Overriding: Subclass provides its own implementation of a method from the parent class.
The program compiles but doesn’t print anything — why?
boolean isRaining = false;
if (isRaining = true) {
System.out.println("Bring an umbrella!");
}
Mistaken assignment in the if condition; should be ==
What is the difference between == and .equals() in Java?
== is for comparing primitive data types or for checking if two object references point to the same instance in memory.
.equals() is for comparing the content or values of objects, especially when dealing with classes like String that have overridden this method, or when you need to define custom equality logic for your own classes.
What is the difference between an interface and an abstract class?
To be learned in class!
String name = null;
if (name.equals("Alice")) {
System.out.println("Hello Alice");
}
This will throw a NullPointerException. You should check for null before calling .equals.