Which of the following will produce an answer that is closest in value to a double, d, while not being greater than d?
A -
(int)Math.min(d);
B -
(int)Math.max(d);
C -
(int)Math.abs(d);
D -
(int)Math.floor(d);
2-
What two statements are true about the result obtained from calling Math.random()?
The result is less than 0.0.
The result is greater than or equal to 0.0..
The result is less than 1.0.
The result is greater than 1.0.
The result is greater than or equal to 1.0.
A -
1 and 2
B -
2 and 3
C -
3 and 4
D -
4 and 5
3-
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
A -
C is printed before exiting with an error message.
B -
Compilation fails.
C -
ABCD
D -
BC is printed before exiting with an error message.
4-
Which four can be thrown using the throw statement?
Error
Event
Object
Throwable
Exception
RuntimeException
A -
1, 2, 3 and 4
B -
2, 4, 5 and 6
C -
2, 3, 4 and 5
D -
1, 4, 5 and 6
5-
What will be the output of the program?
public class Test
{
public static void main (String args[])
{
String str = NULL;
System.out.println(str);
}
}
A -
Runtime Exception
B -
NULL
C -
Code runs but no output
D -
Compile Error
6-
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 -
2 and 3
B -
3 and 4
C -
1 and 4
D -
1 and 2
7-
class Foo
{
class Bar{ }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}
which statement, inserted at line 10, creates an instance of Bar?
A -
Foo.Bar b = f.new Bar();
B -
Bar b = new f.Bar();
C -
Bar b = f.new Bar();
D -
Foo.Bar b = new Foo.Bar();
8-
What will be the output of the program?
public class HorseTest
{
public static void main (String [] args)
{
class Horse
{
public String name; /* Line 7 */
public Horse(String s)
{
name = s;
}
} /* class Horse ends */
Object obj = new Horse("Zippo"); /* Line 13 */
Horse h = (Horse) obj; /* Line 14 */
System.out.println(h.name);
}
} /* class HorseTest ends */
A -
An exception occurs at runtime at line 10.
B -
Compilation fails because of an error on line 7.
C -
It prints "Zippo".
D -
Compilation fails because of an error on line 13.
9-
What will be the output of the program?
class A
{
final public int GetResult(int a, int b) { return 0; }
}
class B extends A
{
public int GetResult(int a, int b) {return 1; }
}
public class Test
{
public static void main(String args[])
{
B b = new B();
System.out.println("x = " + b.GetResult(0, 1));
}
}
A -
Compilation fails.
B -
x = 1
C -
x = 0
D -
An exception is thrown at runtime.
10-
What will be the output of the program?
class SC2
{
public static void main(String [] args)
{
SC2 s = new SC2();
s.start();
}
void start()
{
int a = 3;
int b = 4;
System.out.print(" " + 7 + 2 + " ");
System.out.print(a + b);
System.out.print(" " + a + b + " ");
System.out.print(foo() + a + b + " ");
System.out.println(a + b + foo());
}
String foo()
{
return "foo";
}
}