What will be the output of the program?
public class SqrtExample
{
public static void main(String [] args)
{
double value = -9. System.out.println( Math.sqrt(value));
}
}
What will be the output of the program?
public class NFE
{
public static void main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5"); /* Line 8 */
double d = Double.parseDouble(s);
s = Double.toString(d);
int x = (int) Math.ceil(Double.valueOf(s).doubleValue());
System.out.println(x);
}
catch (NumberFormatException e)
{
System.out.println("bad number");
}
}
}
What will be the output of the program?
public class ExamQuestion{
static int j;
static void methodA(int i)
{
boolean b;
do
{
b = i<| methodB(4); /* Line 9 */
b = i<|| methodB(8); /* Line*/
}while (!b);
}
static boolean methodB(int i)
{
j += i;
return true;
}
public static void main(String[] args)
{
methodA(0);
System.out.println( "j = " + j );
}
}
What will be the output of the program?
public class Test{
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");
}
}
}
What will be the output of the program?
public class Test
{
public static void main(String[] args)
{
final StringBuffer a = new StringBuffer();
final StringBuffer b = new StringBuffer();
new Thread()
{
public void run()
{
System.out.print(a.append("A"));
synchronized(b)
{
System.out.print(b.append("B"));
}
}
}.start();
new Thread()
{
public void run()
{
System.out.print(b.append("C"));
synchronized(a)
{
System.out.print(a.append("D"));
}
}
}.start();
}
}
What will be the output of the program?
public class Test{
public static void stringReplace (String text)
{
text = text.replace ('j' , 'c'); /* Line 5 */
}
public static void bufferReplace (StringBuffer text)
{
text = text.append ("c"); /* Line 9 */
}
public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java"); /* Line*/
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}
What will be the output of the program?
String x = new String("xyz");
String y = "abc";
x = x + y;
How many String objects have been created?Which statement is true given the following?
Double d = Math.random();
What will be the output of the program?
System.out.println(Math.sqrt(-4D));
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 2What will be the output of the program?
try
{
Float f1 = new Float("3.0");
int x = f1.intValue();
byte b = f1.byteValue();
double d = f1.doubleValue();
System.out.println(x + b + d);
}
catch (NumberFormatException e) /* Line 9 */
{
System.out.println("bad number"); /* Line*/
}
What will be the output of the program?
String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}
What will be the output of the program (in jdk1.6 or above)?
public class BoolTest
{
public static void main(String [] args)
{
Boolean b1 = new Boolean("false");
boolean b b2 = b1.booleanValue();
if (!b
{
b2 = true;
System.out.print("x ");
}
if (b1 & b/* Line*/
{
System.out.print("y ");
}
System.out.println("z");
}
}
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );
What will be the output of the program?
class Tree { }
class Pine extends Tree { }
class Oak extends Tree { }
public class Forest{
public static void main (String [] args)
{
Tree tree = new Pine();
if( tree instanceof Pine )
System.out.println ("Pine");
else if( tree instanceof Tree )
System.out.println ("Tree");
else if( tree instanceof Oak )
System.out.println ( "Oak" );
else
System.out.println ("Oops ");
}
}
What will be the output of the program?
public class WrapTest
{
public static void main(String [] args)
{
int result = short s = Long x = new Long("42");
Long y = new Long(42);
Short z = new Short("42");
Short x2 = new Short(s);
Integer y2 = new Integer("42");
Integer z2 = new Integer(42);
if (x == y) /* Line*/
result = if (x.equals(y) ) /* Line*/
result = result + if (x.equals(z) ) /* Line*/
result = result + if (x.equals(x) /* Line*/
result = result + if (x.equals(z) /* Line*/
result = result +
System.out.println("result = " + result);
}
}
Which two statements are true about wrapper or String classes?
What will be the output of the program?
interface Foo{
int k =/* Line 3 */
}
public class Testimplements Foo{
public static void main(String args[])
{
int i;
Testtest= new Test141();
i = test141.k; /* Line*/
i = Test141.k;
i = Foo141.k;
}
}
What will be the output of the program?
class Q{
public static void main(String[] args)
{
int i1 =
int i2 =
String s1 = "7";
System.out.println(i1 + i2 + s1); /* Line 8 */
}
}