Java Programming - Language Fundamentals - Discussion

Discussion Forum : Language Fundamentals - General Questions (Q.No. 1)
1.
Which four options describe the correct default values for array elements of the types indicated?
  1. int -> 0
  2. String -> "null"
  3. Dog -> null
  4. char -> '\u0000'
  5. float -> 0.0f
  6. boolean -> true
1, 2, 3, 4
1, 3, 4, 5
2, 4, 5, 6
3, 4, 5, 6
Answer: Option
Explanation:

(1), (3), (4), (5) are the correct statements.

(2) is wrong because the default value for a String (and any other object reference) is null, with no quotes.

(6) is wrong because the default value for boolean elements is false.

Discussion:
64 comments Page 3 of 7.

Nancy said:   10 years ago
Every class in java is also a data type itself. Since Dog is a user defined class, it is a user defined data type also.

Sunil said:   1 decade ago
Int-0.
Float-0.0.
Char-space.
Boolean-false.
Byte-0.
Short-0.
Long-0.
Double-0.0.

Saikrishna said:   1 decade ago
How Boolean is false only? Please explain.

Pradeep Yadav said:   1 decade ago
Please explain me how can we get the value of class (Dog) object with array in main method from Dog?

Shrikrishn Sharma said:   1 decade ago
Char's default value is not NULL nor 0 in Java.

ShriKrishn Sharma said:   1 decade ago
Default value of char is "null space" it's Unicode is 32. If you want to print it using println function you get a white space over there.

Satya said:   1 decade ago
Can any one explain double default value in Java?

Rajat said:   1 decade ago
Can somebody explain me how dog variable is initialize to null? In netbeans compile is showing an error. As dog variable is not initialized.

Bhavani said:   1 decade ago
The default value for float is only 0.0 in the given question it is 0.0f.

How option B is correct?

Pooja said:   1 decade ago
System-is class of java.lang package.
Out-is static final method of System class. So it is called directly with class name.
(System.out).

And out is also reference of PrintStream class.
println-is method of PrintStream class in java.io package.

So it is called with reference of that class.
(System.out.println).


Post your comments here:

Your comments will be displayed after verification.