Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Easy
Question 36
Consider the code:
- public class Student
- {
- private String name;
- private boolean passed;
- private int marks;
- public static void main(String[] args)
- {
- Student s = new Student();
- System.out.println(s.name+"..."+s.passed+"..."+s.marks);
- }
- }
What is the result ?
-
A
The Compilation Fails
-
B
null...false...0
-
C
null...true...0
-
D
...false...0
Reveal correct answer
Correct answer: B
Explanation
Once we creates an object, every instance variable will be initialized with default values. The default value for String is null, for boolean is false and for int is 0.Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
