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?
- int -> 0
- String -> "null"
- Dog -> null
- char -> '\u0000'
- float -> 0.0f
- boolean -> true
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 6 of 7.
Sivachandran said:
1 decade ago
@Kathirozhi not null and nothing nice answers.
Rehana said:
1 decade ago
What is that \u declared in char?
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.
Suresh said:
1 decade ago
Nice answers
Suganthan.M said:
1 decade ago
Dog - There is no primitive datatype like 'Dog'. It is a User Defined type. By default it will hold null value.
Prathyusha said:
1 decade ago
HI,
No where the "Dog" datatype is mentioned.
If Dog is integer , the default might be -0
If Dog is float , the default might be -0.0f
If Dog is object ,the default might be -null
.... No where it is mentioned whether Dog is wat datatype.
HELP ME IN THIS REGARD.....
No where the "Dog" datatype is mentioned.
If Dog is integer , the default might be -0
If Dog is float , the default might be -0.0f
If Dog is object ,the default might be -null
.... No where it is mentioned whether Dog is wat datatype.
HELP ME IN THIS REGARD.....
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.
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.
Shaswati said:
1 decade ago
How option 4 is correct? I could not understand. Please explain about the default data type of char.
Piyush gadekar said:
1 decade ago
What your are tryng to admit from this program?
Hemangini Kulkarni said:
1 decade ago
Dear Sir,
1) Default value for array element of type char is nothing , not even null
2) Default value for array element of type float is 0.0 not 0.0f
class hello
{
public static void main(String str[])
{
int i[] = new int[5];
float f[] = new float[5];
double d[] = new double[5];
String s[] = new String[5];
char c[] = new char[5];
boolean b[] = new boolean[5];
System.out.println("Hello World");
System.out.println("Integer "+i[0]);
System.out.println("Float "+ f[0]);
System.out.println("Double " + d[0]);
System.out.println("String " + s[0]);
System.out.println("Character " + c[0]);
System.out.println("Boolean " + b[0]);
}
}
1) Default value for array element of type char is nothing , not even null
2) Default value for array element of type float is 0.0 not 0.0f
class hello
{
public static void main(String str[])
{
int i[] = new int[5];
float f[] = new float[5];
double d[] = new double[5];
String s[] = new String[5];
char c[] = new char[5];
boolean b[] = new boolean[5];
System.out.println("Hello World");
System.out.println("Integer "+i[0]);
System.out.println("Float "+ f[0]);
System.out.println("Double " + d[0]);
System.out.println("String " + s[0]);
System.out.println("Character " + c[0]);
System.out.println("Boolean " + b[0]);
}
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers