Which constructs an anonymous inner class instance?
AnswerWhich statement is true about a static nested class?
Answerwhich one create an anonymous inner class from within class Bar?
|
And assuming that the equals() and hashCode() methods are properly implemented, if the output is "x = 1111", which of the following statements will always be true?
x = 0;
if (x1.hashCode() != x2.hashCode() ) x = x + 1;
if (x3.equals(x4) ) x = x + 10;
if (!x5.equals(x6) ) x = x + 100;
if (x7.hashCode() == x8.hashCode() ) x = x + 1000;
System.out.println("x = " + x);
Answer
Which two statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden?
What will be the output of the program?
public class Test
{
private static float[] f = new float[2];
public static void main (String[] args)
{
System.out.println("f[0] = " + f[0]);
}
}
Answer
What will be the output of the program?
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);
Answer
Which statement is true?
public class While
{
public void loop()
{
int x= 0;
while ( 1 ) /* Line 6 */
{
System.out.print("x plus one is " + (x + 1)); /* Line 8 */
}
}
}
Answer
Which two of the following are legal declarations for nonnested classes and interfaces?
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");
}
}
Answer
What will be the output of the program?
int i = (int) Math.random();
Answer
Select how you would start the program to cause it to print: Arg is 2
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);
}
}
Answer
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?
AnswerWhich two can be used to create a new Thread?
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();
}
}
Answer
Which class or interface defines the wait(), notify(),and notifyAll() methods?
AnswerWhich of the following will directly stop the execution of a Thread?
AnswerWhat 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"));
}
}
Answer
Which of the following statements about the hashcode() method are incorrect?
Which interface provides the capability to store objects using a key-value pair?
Answer© 2017 QuizBucket.org