- Aweakly typed
- Bstrogly typed
- Cmoderate typed
- D None of these
Java is a strongly typed language. This means that the type of a variable is known at compile time and once a variable is declared with a certain type, it cannot be assigned a value of a different type without an explicit cast.
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.
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.
Option A is correct. A public access modifier is acceptable. The method prototypes in an interface are all abstract by virtue of their declaration, and should not be declared abstract.
Option B is wrong. The final modifier means that this method cannot be constructed in a subclass. A finalmethod cannot be abstract.
Option C is wrong. static is concerned with the class and not an instance.
Option D is wrong. protected is not permitted when declaring a method of an interface. See information below.
Member declarations in an interface disallow the use of some declaration modifiers; you cannot use transient, volatile, or synchronized in a member declaration in an interface. Also, you may not use the private and protected specifiers when declaring members of an interface.
Option D is correct. A runtime error will occur owning to the main method of the code fragment not being declared static:
Exception in thread "main" java.lang.NoSuchMethodError: main
The Java Language Specification clearly states: "The main method must be declared public, static, and void. It must accept a single argument that is an array of strings."
An exception is thrown because at some point in (System.out.print(" " + argh[y]);), the value of x will be equal to y, resulting in an attempt to access an index out of bounds for the array. Remember that you can access only as far as length - 1, so loop logical tests should use x < someArray.length as opposed to x < = someArray.length.
The loops use the array sizes (length).
It produces 11 lines of output as given below.
D:\Java>javac Test.java D:\Java>java Test size = 1 size = 2 size = 3 size = 4 size = 2 size = 3 size = 3 size = 4 size = 5 size = 6 size = 7
Therefore, 11 is the answer.
The names array is initialized with five null elements. Then elements 0 and 1 are assigned the String values "a" and "b" respectively (the command-line arguments passed to main). Elements of names array 2, 3, and 4 remain unassigned, so they have a value of null.
Yes, like
except ( NameError, SyntaxError, ...)