D. c = null
b = false
f = 0.0
Code -
public class FieldInit {
Character c;
boolean b;
float f;
void printAll() {
System.out.println("c = "+c);
System.out.println("b = "+b);
System.out.println("f = "+f);
}
public static void main(String[] args) {
FieldInit f = new FieldInit();
f.printAll();
}
}
The answer is the letter D, if you don't give a variable a value, it will have the default value.
Character -> Default value is null
Boolean -> Default value is false
Float -> Default value is 0.0
OBS: Do not memorize the results of the questions, because there are similar questions, this one for example has a variation that changes "Character" for "char", a variable type "char" does not print anything instead of null. Try to understand how the code works, so you'll get it right when a similar question falls on the test.
Basically, for all reference types (String, Object, Integer, Character, ...) are all default null while all primitive types are equivalently equals to 0 (char --> \u0000, boolean --> false, int --> 0, float --> 0.0).
upvoted 2 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
DriftKing
4 months, 1 week agoDriftKing
4 months, 1 week agoiSnover
1 year, 3 months agoalex_au
1 year, 3 months ago