Which of the following statements about the hashcode() method are incorrect?
The value returned by hashcode() is used in some collection classes to help locate objects.
The hashcode() method is required to return a positive int value.
The hashcode() method in the String class is the one inherited from Object.
Two new empty String objects will produce identical hashcodes.
A -
1 and 2
B -
2 and 3
C -
3 and 4
D -
1 and 4
2-
What will be the output of the program?
public class TestObj
{
public static void main (String [] args)
{
Object o = new Object() /* Line 5 */
{
public boolean equals(Object obj)
{
return true;
}
} /* Line 11 */
System.out.println(o.equals("Fred"));
}
}
A -
It prints "true".
B -
It prints "Fred".
C -
An exception occurs at runtime.
D -
Compilation fails
3-
Which of the following will directly stop the execution of a Thread?
A -
wait()
B -
notify()
C -
notifyall()
D -
exits synchronized code
4-
Which class or interface defines the wait(), notify(),and notifyAll() methods?
A -
Object
B -
Thread
C -
Runnable
D -
Class
5-
What will be the output of the program?
public class ThreadDemo
{
private int count = 1;
public synchronized void doSomething()
{
for (int i = 0; i < 10; i++)
System.out.println(count++);
}
public static void main(String[] args)
{
ThreadDemo demo = new ThreadDemo();
Thread a1 = new A(demo);
Thread a2 = new A(demo);
a1.start();
a2.start();
}
}
class A extends Thread
{
ThreadDemo demo;
public A(ThreadDemo td)
{
demo = td;
}
public void run()
{
demo.doSomething();
}
}
A -
It will print the numbers 0 to 19 sequentially
B -
It will print the numbers 1 to 20 sequentially
C -
It will print the numbers 1 to 20, but the order cannot be determined
D -
The code will not compile.
6-
Which two can be used to create a new Thread?
Extend java.lang.Thread and override the run() method.
Extend java.lang.Runnable and override the start() method.
Implement java.lang.Thread and implement the run() method.
Implement java.lang.Runnable and implement the run() method.
Implement java.lang.Thread and implement the start() method.
A -
1 and 2
B -
2 and 3
C -
1 and 4
D -
3 and 4
7-
The following block of code creates a Thread using a Runnable target:
Runnable target = new MyRunnable();
Thread myThread = new Thread(target);
Which of the following classes can be used to create the target, so that the preceding code compiles correctly?
A -
public class MyRunnable extends Runnable{public void run(){}}
B -
public class MyRunnable extends Object{public void run(){}}
C -
public class MyRunnable implements Runnable{public void run(){}}
D -
public class MyRunnable implements Runnable{void run(){}}
8-
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);
}
}
Select how you would start the program to cause it to print: Arg is 2
A -
java Myfile 222
B -
java Myfile 1 2 2 3 4
C -
java Myfile 1 3 2 2
D -
java Myfile 0 1 2 3
9-
What will be the output of the program?
int i = (int) Math.random();
A -
i = 0
B -
i = 1
C -
Value of i is undetermined
D -
Statement causes a compile error
10-
What will be the output of the program?
class A
{
public A(int x){}
}
class B extends A { }
public class test
{
public static void main (String args [])
{
A a = new B();
System.out.println("complete");
}
}