Java · Question 5 · Easy

What is the default value of an int instance variable (field) that is declared but not explicitly initialised in a Java class?

  1. 0
  2. null
  3. Garbage value
  4. -1
Answer and explanation

Answer: A. 0

Explanation: Java gives every field a default value: 0 for numeric types, false for boolean and null for references. Only local variables have no default and must be assigned before use.

Previous: What will be the output of the following Java program? · Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge