JAVA QUESTIONS 1 (24.1.22) : A. 1, 2, 4 B. 2, 4, 5 C. 2, 3, 4 D. All Are Correct. Answer: Option A
JAVA QUESTIONS 1 (24.1.22) : A. 1, 2, 4 B. 2, 4, 5 C. 2, 3, 4 D. All Are Correct. Answer: Option A
22)
1.Which three are legal array declarations?
int [] myScores [];
char [] myChars;
int [6] myScores;
Dog myDogs [];
Dog myDogs [7];
A. 1, 2, 4
B. 2, 4, 5
C. 2, 3, 4
2.Which one of the following will declare an array and initialize it with five numbers?
A. Array a = new Array(5);
B. int [] a = {23,22,21,20,19};
B. 1, 3, 6
C. 3, 5
D. 5 only
Answer: Option B
4.Which two are equal?
1. 32/4
2. (8 >> 2) << 4
3. 2^5
4. 128 >>> 2
5. 2 >> 5
A. 1 and 2
B. 2 and 4
C. 1 and 3
D. 2 and 3
Answer: Option B
A. finally
B. exception finished
B. throws Exception
C. catch ( Exception e )
D. throws RuntimeException
Answer: Option B
System.out.println(o.equals("Fred"));
}
}
A. It prints "true".
B. It prints "Fred".
D. Compilation fails
Answer: Option D
10.
class Test
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
B. After line 8
D. When the instance running this code is made eligible for garbage collection.
Answer: Option D
11.
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
B. java Myfile 1 2 2 3 4
C. java Myfile 1 3 2 2
D. java Myfile 0 1 2 3
Answer: Option C
A. int
B. byte
C. long
D. double
Answer: Option D
A. 0
B. 1
C. 2
D. Compilation fails.
Answer: Option D
14.Which two statements are true for any concrete class implementing the java.lang.Runnable
interface?
1. You can extend the Runnable interface as long as you override the public run() method.
2. The class must contain a method called run() from which all code for that thread will be
initiated.
3. The class must contain an empty public void method named run().
4. The class must contain a public void method named runnable().
5. The class definition must include the words implements Threads and contain a method
called run().
6. The mandatory method must be public, with a return type of void, must be called run(),
and cannot take any arguments.
A. 1 and 3
B. 2 and 4
C. 1 and 5
D. 2 and 6
Answer: Option D
15.
D. "odd" will be output for odd values of x, and "even" for even values.
Answer: Option A
B. 2 and 3
C. 3 and 4
D. 2 and 4
Answer: Option B
A. NULL
B. Compile Error
D. Runtime Exception
Answer: Option B
B. 2 and 3
C. 3 and 4
D. 1 and 3
Answer: Option C
19.Which three guarantee that a thread will leave the running state?
1. yield()
2. wait()
3. notify()
4. notifyAll()
5. sleep(1000)
6. aLiveThread.join()
7. Thread.killThread()
A. 1, 2 and 4
B. 2, 5 and 6
C. 3, 4 and 7
D. 4, 5 and 7
Answer: Option B
A. finished
B. Compiliation fails.