What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}
Answer
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
AnswerWhat will be the output of the program?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 4; z++)
{
switch (z)
{
case x: System.out.print("0 ");
default: System.out.print("def ");
case x-1: System.out.print("1 ");
break;
case x-2: System.out.print("2 ");
}
}
}
}
Answer
What will be the output of the program?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 3; z++)
{
switch (z)
{
case y: System.out.print("0 "); /* Line 11 */
case x-1: System.out.print("1 "); /* Line 12 */
case x: System.out.print("2 "); /* Line 13 */
}
}
}
}
Answer
What will be the output of the program?
public class Switch2
{
final static short x = 2;
public static int y = 0;
public static void main(String [] args)
{
for (int z=0; z < 3; z++)
{
switch (z)
{
case x: System.out.print("0 ");
case x-1: System.out.print("1 ");
case x-2: System.out.print("2 ");
}
}
}
}
Answer
Which two are acceptable types for x?
switch(x)
{
default:
System.out.println("Hello");
}
Which is a valid declaration within an interface?
AnswerYou want a class to have access to members of another class in the same package. Which is the most restrictive access that accomplishes this objective?
AnswerWhat is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
AnswerWhat will be the output of the program?
public class ExamQuestion7
{
static int j;
static void methodA(int i)
{
boolean b;
do
{
b = i<10 | methodB(4); /* Line 9 */
b = i<10 || methodB(8); /* Line 10 */
}while (!b);
}
static boolean methodB(int i)
{
j += i;
return true;
}
public static void main(String[] args)
{
methodA(0);
System.out.println( "j = " + j );
}
}
Answer
What will be the output of the program?
int i = 1, j = 10;
do
{
if(i++ > --j) /* Line 4 */
{
continue;
}
} while (i < 5);
System.out.println("i = " + i + "and j = " + j); /* Line 9 */
Answer
What will be the output of the program?
public class Test178
{
public static void main(String[] args)
{
String s = "foo";
Object o = (Object)s;
if (s.equals(o))
{
System.out.print("AAA");
}
else
{
System.out.print("BBB");
}
if (o.equals(s))
{
System.out.print("CCC");
}
else
{
System.out.print("DDD");
}
}
}
Answer
What will be the output of the program?
public class ObjComp
{
public static void main(String [] args )
{
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;
if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;
System.out.println("result = " + result);
}
}
Answer
Which statement is true about assertions in the Java programming language?
AnswerWhich statement is true?
AnswerWhich statement is true?
AnswerWhat will be the output of the program?
class MyThread extends Thread
{
public static void main(String [] args)
{
MyThread t = new MyThread();
Thread x = new Thread(t);
x.start(); /* Line 7 */
}
public void run()
{
for(int i = 0; i < 3; ++i)
{
System.out.print(i + "..");
}
}
}
Answer
What will be the output of the program?
class Happy extends Thread
{
final StringBuffer sb1 = new StringBuffer();
final StringBuffer sb2 = new StringBuffer();
public static void main(String args[])
{
final Happy h = new Happy();
new Thread()
{
public void run()
{
synchronized(this)
{
h.sb1.append("A");
h.sb2.append("B");
System.out.println(h.sb1);
System.out.println(h.sb2);
}
}
}.start();
new Thread()
{
public void run()
{
synchronized(this)
{
h.sb1.append("D");
h.sb2.append("C");
System.out.println(h.sb2);
System.out.println(h.sb1);
}
}
}.start();
}
}
Answer
What will be the output of the program?
public class Test
{
public static void main (String[] args)
{
String foo = args[1];
String bar = args[2];
String baz = args[3];
System.out.println("baz = " + baz); /* Line 8 */
}
}
And the command line invocation:
> java Test red green blue
AnswerWhich of the following are Java reserved words?
© 2017 QuizBucket.org