|
Home ► Placements ► Interview Questions ► Java Interview Questions And Answers ►Java Interview Questions On Arrays and Data Types ▼
Java Interview Questions On Arrays and Data Types |
7. What is the output on the screen, When you place the following code inside a main() method, if you
compile and run? ( note: please use for() loop ).
String stringArray[]= new String[4];
[a] A zero is printed on the screen
[b] A blank is printed on the screen
[c] Compile time error
[d] A null is printed on the screen
Answer
[d] A null is printed on the screen |
8. Select all the correct declarations, or declaration and initializations of an array?
[a] String str[];
[b] String str[5] = new String[5];
[c] String str[]= new String[]{"string1", "string2", "string3", "string4", "string5"};
[d] String str[] = {"string1","string2", "string3", "string4", "string5"};
Answer
[a] String str[];
[c] String str[] = new String[]{"string1", "string 2", "string3", "string4", "string5"};
[d] String str[] = {"string1","string2", "string3", "string4", "string5"}; |
9. What is the output when you compile and run the following code?
public class StatAarray {
static char staticArray[]=new char[5];
public static void main(String args[]) {
System.out.println(staticArray[1]);
}
}
[a] Prints 0 to 4 on the screen
[b] Compile time and run time error
[c] Prints \u0000 on the screen
[d] Compile time error
[e] Prints nothing on the screen
Answer
[e] Prints nothing on the screen |
10. Select all the correct answers from the following?
[a] char c = new [5][5];
[b] int i [][] = new int [5][5];
[c] int i [][] = new int {{1,2},{1,4}};
[d] float [][] f = {{1,2},{3,4}};
[e] Double [][]d = {{new Double(10.5d), new Double (15.0d)}, new Double(20.0d),new
Double(30.0d)};
Answer
[b] int i [][] = new int [5][5];
[d] float [][] f = {{1,2},{3,4}}; |
|
|