Java
Java
protected void methoda(double d1); Answer & Explanation Answer: Option E Explanation: Option A is correct. A public access modifier is acceptable. The method prototyp es in an interface are all abstract by virtue of their declaration, and should n ot be declared abstract. Option B is wrong. The final modifier means that this method cannot be construct ed in a subclass. A final method 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 inte rface. See information below. Member declarations in an interface disallow the use of some declaration modifie rs; 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
2. Which one of the following will declare an array and initialize it with five num bers? A. Array a = new Array(5); B. int [] a = {23,22,21,20,19}; C. int a [] = new int(5); D. int [5] array; Answer & Explanation Answer: Option D Explanation: 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 Arr ay, passing the integer value 5 to the object's constructor. If you don't see th e 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 initia lization. Option D is wrong (and will not compile) because it declares an array with a siz e. Arrays must never be given a size when declared. 3.public class Foo {
public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } } A. Finally B. Compilation fails. C. The code runs with no output. D. An exception is thrown at runtime. Answer & Explanation Answer: Option A Explanation: If you put a finally block after a try and its associated catch blocks, then onc e execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances: An exception arising in the finally block itself. The death of the thread. The use of System.exit() Turning off the power to the CPU. I suppose the last three could be classified as VM shutdown 4.