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 2 of 7.

Sundar said:   1 decade ago
@Shaswati

It is nothing but a class created by a user.

Ex: Dog, Student, Car etc.

The question is 'what will be default value?'.


Student objStud1;

Here objStud1 will contain 'null' value by default.

Usha said:   1 decade ago
That shows in hexa representation
java is same as c ,we can say this by this because java uses the syntax of c. for more advantages and comfortable they created java as platform independent

Ajay surwade said:   3 years ago
@Kishor.

In java any word within double quote " " is treated as a string, hence string "null" means there is a word null &.

If we assign String = null, this means no value means no word i.e. blank.
(18)

Thiru said:   1 decade ago
char in Java is an unsigned 16 bit numerical value representing a two-byte Unicode character.

Since you left it as default, your char is 0, or u\0000. This is the Unicode NULL value.

AVINASH said:   9 years ago
Int-0.
Byte-0.
Short-0.
Long-0.
Double-0.0 or 0.0d or 0.0D.
Float-0.0f or 0.0F. Here f means float type default value 0.0.
Char-'\u0000' or space.
Boolean-False.
String - null.
(1)

Dilip kumar said:   1 decade ago
class A
{
...
...
}
class B
{
A Dog=new A();
}

Here class a is non premitive datatype and Dog is as object reference variable which holds the object referenced.

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.

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.

Nabbu said:   1 decade ago
Is that Dog is a user define data type.
Or we can say that Dog is a object of a class.
class A
{
...
...
}
class B
{
A Dog=new A();
}

Kathirozhi said:   1 decade ago
Plese correctly tell the char default value is nothing or not null or the answer in the question please help to understand.


Post your comments here:

Your comments will be displayed after verification.