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 1 of 7.
Boopalan v said:
2 decades ago
Is there any primitive data type named Dog?
SIJO.S said:
1 decade ago
What is the use of data type 'Dog'. I didnt heard about that!
Sundar said:
1 decade ago
Hi All,
Dog - There is no primitive datatype like 'Dog'. It is a User Defined type (a class created by User). By default it will hold null value.
For example:
public class Dog
{
//...
}
Dog myDog;
Here myDog will contain 'null' value by default.
Hope you understand. Have a nice day!
Dog - There is no primitive datatype like 'Dog'. It is a User Defined type (a class created by User). By default it will hold null value.
For example:
public class Dog
{
//...
}
Dog myDog;
Here myDog will contain 'null' value by default.
Hope you understand. Have a nice day!
Garima S said:
1 decade ago
Not able to undestand the given question.
Can anyone please explain it to me?
Can anyone please explain it to me?
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]);
}
}
Piyush gadekar said:
1 decade ago
What your are tryng to admit from this program?
Shaswati said:
1 decade ago
How option 4 is correct? I could not understand. Please explain about the default data type of char.
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.
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.....
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers