Bird
0
0

What will be the output of this Java code?

medium📝 Predict Output Q13 of 15
Java - Constructors
What will be the output of this Java code?
class Car {
  String model;
}
public class Test {
  public static void main(String[] args) {
    Car c = new Car();
    System.out.println(c.model);
  }
}
Anull
BEmpty string
CCompilation error
DRuntime exception
Step-by-Step Solution
Solution:
  1. Step 1: Understand default constructor usage

    No constructor is defined, so Java provides a default constructor that sets no initial values.
  2. Step 2: Check default value of uninitialized String

    Instance variable 'model' is a String and defaults to null if not set.
  3. Final Answer:

    null -> Option A
  4. Quick Check:

    Uninitialized String = null by default [OK]
Quick Trick: Uninitialized object fields default to null in Java [OK]
Common Mistakes:
  • Expecting empty string instead of null
  • Thinking default constructor sets values automatically
  • Assuming compilation or runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes