Which will legally declare, construct and initialize an array?
A. int [] mylist = { "1", "2", "3"};
B. int [] mylist = (5, 8, 2);
C. int mylist [] [] = {4, 9, 7, 0};
D. int mylist [] = { 4, 3, 7};
E. int [] myList = [3, 5, 6];
F. int myList [] = {4; 6; 5};
Answer: D
The rest are wrong because
A: The array is of type int but the values assigned are String literals.
B: Curly braces should be used instead of ( ).
C: Provides initial values for one dimension, even though the array is two dimensional.
E: Curly braces should be used instead of [].
F. Commas should be used to seperate the values.
Question 5
Consider the following lines of code:
int [] x = new int[25];
After execution, which statement or statements are true?
A. x[24] is 0.
B. x[24] is undefined.
C. x[25] is 0.
D. x[0] is null.
E. x.length is 25.
Answer : A, E
The array index is from 0 to 24. It has 25 elements which are all initialized to the default value of the data type of the array.
int [] x = new int[25];
After execution, which statement or statements are true?
A. x[24] is 0.
B. x[24] is undefined.
C. x[25] is 0.
D. x[0] is null.
E. x.length is 25.
Answer : A, E
The array index is from 0 to 24. It has 25 elements which are all initialized to the default value of the data type of the array.
Question 4
If all three top - level elements occur in one source file, they must appear in which order?
A. Imports, package declaration, classes
B. Classes, Imports, package declaration
C. Package declaration should come first; order for imports and class definitions is not
significant.
D. Package declaration, imports, classes
E. Imports must come first; order for package declaration and class definitions is not significant.
Answer: D
A. Imports, package declaration, classes
B. Classes, Imports, package declaration
C. Package declaration should come first; order for imports and class definitions is not
significant.
D. Package declaration, imports, classes
E. Imports must come first; order for package declaration and class definitions is not significant.
Answer: D
Question 3
Which of the following signatures are valid for the main method entry point of the application?
A. public static void main()
B. public static void main(String arg[])
C. public void main(String [] arg)
D. public static void main(String [] args)
E. public static int main(String [] arg)
Answer: B, D
A. public static void main()
B. public static void main(String arg[])
C. public void main(String [] arg)
D. public static void main(String [] args)
E. public static int main(String [] arg)
Answer: B, D
Question 2
Choose valid identifiers from those listed below.
A.BigO1LongStringWithMeaninglessName
B.$Int
C.bytes
D.$1
E.finalist
Answer: A, B, C, D, E
An identifier must begin with a letter, a dollar sign ($) or an underscore; subsequent characters maybe letters, dollar signs, underscores or digits.
A.BigO1LongStringWithMeaninglessName
B.$Int
C.bytes
D.$1
E.finalist
Answer: A, B, C, D, E
An identifier must begin with a letter, a dollar sign ($) or an underscore; subsequent characters maybe letters, dollar signs, underscores or digits.
Subscribe to:
Posts (Atom)