What is the narrowest valid returnType for methodA in line 3?
public class ReturnIt
{
returnType methodA(byte x, double y) /* Line 3 */
{
return (long)x / y * 2;
}
}
A -
int
B -
byte
C -
long
D -
double
3-
Which two cause a compiler error?
float[ ] f = new float(3);
float f2[ ] = new float[ ];
float[ ]f1 = new float[3];
float f3[ ] = new float[3];
float f5[ ] = {1.0f, 2.0f, 2.0f};
A -
2, 4
B -
3, 5
C -
4, 5
D -
1, 2
4-
What will be the output of the program?
public class Test
{
public static void main(String args[])
{
class Foo
{
public int i = 3;
}
Object o = (Object)new Foo();
Foo foo = (Foo)o;
System.out.println("i = " + foo.i);
}
}
A -
i = 3
B -
Compilation fails.
C -
i = 5
D -
A ClassCastException will occur.
5-
What will be the output of the program?
public class A
{
void A() /* Line 3 */
{
System.out.println("Class A");
}
public static void main(String[] args)
{
new A();
}
}
A -
Class A
B -
Compilation fails.
C -
An exception is thrown at line 3.
D -
The code executes with no output.
6-
What will be the output of the program?
class Test
{
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( ++x > 2 ) || (++y > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
}
A -
5 3
B -
8 2
C -
8 3
D -
8 5
7-
import java.awt.Button;
class CompareReference
{
public static void main(String [] args)
{
float f = 42.0f;
float [] f1 = new float[2];
float [] f2 = new float[2];
float [] f3 = f1;
long x = 42;
f1[0] = 42.0f;
}
}
which three statements are true?
f1 == f2
f1 == f3
f2 == f1[1]
x == f1[0]
f == f1[0]
A -
1, 2 and 3
B -
2, 4 and 5
C -
3, 4 and 5
D -
1, 4 and 5
8-
What will be the output of the program?
public class MyProgram
{
public static void main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
A -
Nothing. The program will not compile because no exceptions are specified.
B -
Nothing. The program will not compile because no catch clauses are specified.
C -
Hello world.
D -
Hello world Finally executing
9-
System.out.print("Start ");
try
{
System.out.print("Hello world");
throw new FileNotFoundException();
}
System.out.print(" Catch Here "); /* Line 7 */
catch(EOFException e)
{
System.out.print("End of file exception");
}
catch(FileNotFoundException e)
{
System.out.print("File not found");
}
and given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code?
A -
The code will not compile.
B -
Code output: Start Hello world File Not Found.
C -
Code output: Start Hello world End of file exception.
D -
Code output: Start Hello world Catch Here File not found.
10-
Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?