Java Programming - Objects and Collections - Discussion
Discussion Forum : Objects and Collections - Finding the output (Q.No. 6)
6.
What will be the output of the program?
public class Test
{
private static float[] f = new float[2];
public static void main (String[] args)
{
System.out.println("f[0] = " + f[0]);
}
}
Answer: Option
Explanation:
The choices are between Option A and B, what this question is really testing is your knowledge of default values of an initialized array. This is an array type float i.e. it is a type that uses decimal point numbers therefore its initial value will be 0.0 and not 0
Discussion:
5 comments Page 1 of 1.
Arif Shaikh said:
9 years ago
How come a private member is accessed in the main function?
(3)
@jyotiG said:
1 decade ago
Why 0.0 not 0F, as per previous questions 9 of general ques. of Collection topic 0.0 indicate double value because any literal number with a decimal point you declare the computer will implicitly cast to double unless you include "F or f".
(2)
Saswata said:
8 years ago
I also agree @Arif.
(2)
Sneha said:
6 years ago
Here, f = new float[2]; is array size.
(1)
Josh b said:
10 years ago
This is testing knowledge of the format in which 0 is printed. The value 0 and 0 of are the same.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers