Java Basics
OOP Concepts
Debug This!
100

What keyword is used to define a class?

class

100

What does OOP stand for?

Object-Oriented Programming

100

Identify the error: int x = "5"; 

"5" is a String, not an int

200

What data type is used to store a true/false value?

boolean

200

Name two principles of OOP

Inheritance, Encapsulation, Polymorphism, Abstraction

200

What’s wrong here? 

if (x = 10) {

    System.out.println("Ten");

}

= is assignment; should be ==

300

Result of this code?

int x = 5;

int y = 2;

double result = x / y;

System.out.println(result);

2.0

300

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.

300

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 ==

400

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.

400

What is the difference between an interface and an abstract class?

To be learned in class!

400

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.