Machine-translated by Google. Questions are authored in English.
Top

Language Fundamentals - General Questions Questions and Answers

11.

Which three are legal array declarations?

1.int [] myScores [];

2.char [] myChars;

3.int [6] myScores;

4.Dog myDogs [];

5.Dog myDogs [7];

Answer: A

(1), (2), and (4) are legal array declarations. With an array declaration, you can place the brackets to the right or left of the identifier. Option A looks strange, but it's perfectly legal to split the brackets in a multidimensional array, and place them on both sides of the identifier. Although coding this way would only annoy your fellow programmers, for the exam, you need to know it's legal.

(3) and (5) are wrong because you can't declare an array with a size. The size is only needed when the array is actually instantiated (and the JVM needs to know how much space to allocate for the array, based on the type of array and the size).

Please log in or register to report this question.

12.

Which three are valid declarations of a float?

1.float f1 = -343;

2.float f2 = 3.14;

3.float f3 = 0x12345;

4.float f4 = 42e7;

5.float f5 = 2001.0D;

6.float f6 = 2.81F;

Answer: C

(1) and (3) are integer literals (32 bits), and integers can be legally assigned to floats (also 32 bits). (6) is correct because (F) is appended to the literal, declaring it as a float rather than a double (the default for floating point literals).

(2), (4),and (5) are all doubles.

Please log in or register to report this question.

13.

Which is a valid keyword in java?

Answer: A

interface is a valid keyword.

Option B is wrong because although "String" is a class type in Java, "string" is not a keyword.

Option C is wrong because "Float" is a class type. The keyword for the Java primitive is float.

Option D is wrong because "unsigned" is a keyword in C/C++ but not in Java.

Please log in or register to report this question.

14.

Which one of the following will declare an array and initialize it with five numbers?

Answer: B

Option B is the legal way to declare and initialize an array with five elements.

Option A is wrong because it shows an example of instantiating a class named Array, passing the integer value 5 to the object's constructor. If you don't see the brackets, you can be certain there is no actual array object! In other words, an Array object (instance of class Array) is not the same as an array object.

Option C is wrong because it shows a legal array declaration, but with no initialization.

Option D is wrong (and will not compile) because it declares an array with a size. Arrays must never be given a size when declared.

Please log in or register to report this question.

Answer: C

Correct answer: boolean b3 = false;

A boolean accepts only the literals true and false. Java performs no conversion between numbers and booleans, so 0 is not accepted - the C idiom of zero meaning false does not carry over. 'false' in single quotes is a char literal and in any case too long to be one, Boolean.false() is not a method, and no is an undeclared identifier.

Please log in or register to report this question.

16.

Which is a reserved word in the Java programming language?

Answer: B

The word "native" is a valid keyword, used to modify a method declaration.

Option A, D and E are not keywords. Option C is wrong because the keyword for subclassing in Java is extends, not 'subclasses'.

Please log in or register to report this question.

Answer: B

All the words in option B are among the 49 Java keywords. Although goto reserved as a keyword in Java, goto is not used and has no function.

Option A is wrong because the keyword for the primitive int starts with a lowercase i.

Option C is wrong because "virtual" is a keyword in C++, but not Java.

Option D is wrong because "constant" is not a keyword. Constants in Java are marked static and final.

Option E is wrong because "include" is a keyword in C, but not in Java.

Please log in or register to report this question.

Answer: A

Option A sets the String reference to null.

Option B is wrong because null cannot be in single quotes.

Option C is wrong because there are multiple characters between the single quotes ('abc').

Option D is wrong because you can't cast a char (primitive) to a String (object).

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Language Fundamentals - General Questions Questions and Answers || Language Fundamentals - General Questions MCQ Questions and Answers || Language Fundamentals - General Questions GK Questions and Answers || Language Fundamentals - General Questions GK MCQ Questions || Language Fundamentals - General Questions Multiple Choice Questions and Answers || Language Fundamentals - General Questions GK || GK on Language Fundamentals - General Questions || Java Programming Questions and Answers || Java Programming MCQ Questions and Answers || Java Programming GK Questions and Answers || GK on Java Programming