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?
- 0
- null
- Garbage value
- -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
- What will be the output of the following Java program?
- Which Java keyword, when applied to a class, prevents any other class from…
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
- What will be the output of the following Java program?
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