In an assert statement, the expression after the colon ( : ) can be any Java expression.
B -
If a switch block has no default, adding an assert default is considered appropriate.
C -
In an assert statement, if the expression after the colon ( : ) does not have a value, the assert's error message will be empty.
D -
It is appropriate to handle assertion failures using a catch clause.
2-
Which three statements are true?
Assertion checking is typically enabled when a program is deployed.
It is never appropriate to write code to handle failure of an assert statement.
Assertion checking is typically enabled during program development and testing.
Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
A -
1, 2 and 4
B -
2, 3 and 5
C -
3, 4 and 5
D -
1, 2 and 5
3-
public class Test2
{
public static int x;
public static int foo(int y)
{
return y * 2;
}
public static void main(String [] args)
{
int z = 5;
assert z > 0; /* Line 11 */
assert z > 2: foo(z); /* Line 12 */
if ( z < 7 )
assert z > 4; /* Line 14 */
switch (z)
{
case 4: System.out.println("4 ");
case 5: System.out.println("5 ");
default: assert z < 10;
}
if ( z < 10 )
assert z > 4: z++; /* Line 22 */
System.out.println(z);
}
}
which line is an example of an inappropriate use of assertions?
A -
Line 11
B -
Line 12
C -
Line 14
D -
Line 22
4-
public class Test
{
public void foo()
{
assert false; /* Line 5 */
assert false; /* Line 6 */
}
public void bar()
{
while(true)
{
assert false; /* Line 12 */
}
assert false; /* Line 14 */
}
}
What causes compilation to fail?
A -
Line 5
B -
Line 14
C -
Line 12
D -
Line 6
5-
What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random( ));
A -
2
B -
3
C -
4
D -
2.5
6-
Which of the following would compile without error?
A -
int a = Math.abs(-5);
B -
int b = Math.abs(5.0);
C -
int c = Math.abs(5.5F);
D -
int d = Math.abs(5L);
7-
Which of the following are valid calls to Math.max?
Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
A -
1, 2 and 4
B -
2, 3 and 4
C -
1, 2 and 3
D -
2, 3 and 4
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?
String x = new String("xyz");
String y = "abc";
x = x + y;
How many String objects have been created?
A -
2
B -
3
C -
4
D -
5
10-
What will be the output of the program?
public class WrapTest
{
public static void main(String [] args)
{
int result = 0;
short s = 42;
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 13 */
result = 1;
if (x.equals(y) ) /* Line 15 */
result = result + 10;
if (x.equals(z) ) /* Line 17 */
result = result + 100;
if (x.equals(x2) ) /* Line 19 */
result = result + 1000;
if (x.equals(z2) ) /* Line 21 */
result = result + 10000;
System.out.println("result = " + result);
}
}