NEW
Font size
WorksheetsJAVA QUIZ
Total questions: 20
Worksheet time: 10mins
Which one of these lists contains only Java programming language keywords?
class, if, void, long, Int, continue
goto, instanceof, native, finally, default, throws
try, virtual, throw, final, volatile, transient
strictfp, constant, super, implements, do
Which is a reserved word in the Java programming language?
method
native
subclasses
reference
Which is a valid keyword in java?
interface
string
Float
unsigned
Which three are legal array declarations?
1.int [] myScores [];
2.char [] myChars;
3.int [6] myScores;
4.Dog myDogs [];
5.Dog myDogs [7];
1, 2, 4
2, 4, 5
2, 3, 4
All are correct.
Which is the valid declarations within an interface definition?
public double methoda();
public final double methoda();
static void methoda(double d1);
protected void methoda(double d1);
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
What will be the output of the program?
class Equals
{
public static void main(String [] args)
{
int x = 100;
double y = 100.1;
boolean b = (x = y); /* Line 7 */
System.out.println(b);
}
}
true
false
Compilation fails
An exception is thrown at runtime
What will be the output of the program?
class Bitwise
{
public static void main(String [] args)
{
int x = 11 & 9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}
0
7
8
14
What will be the output of the program?
class SSBool
{
public static void main(String [] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = true;
if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 /
System.out.print("ok ");
if ( b1 & b2 | b2 & b3 | b2 | b1 ) /Line 10*/
System.out.println("dokey");
}
}
ok
dokey
ok dokey
No output is produced
What allows the programmer to destroy an object x?
x.delete()
x.finalize()
Runtime.getRuntime().gc()
Only the garbage collection system can destroy an object.
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
public
private
protected
transient
Which three form part of correct array declarations?
1.public int a [ ]
2.static int [ ] a
3.public [ ] int a
4.private int a [3]
5.private int [3] a [ ]
6.public final int [ ] a
1, 3, 4
2, 4, 5
1, 2, 6
2, 5, 6
Which three are valid method signatures in an interface?
1.private int getArea();
2.public float getVol(float x);
3.public void main(String [] args);
4.public static void main(String [] args);
5.boolean setFlag(Boolean [] test);
1 and 2
2, 3 and 5
3, 4, and 5
2 and 4
Suppose that you would like to create an instance of a new Map that has an iteration order that is the same as the iteration order of an existing instance of a Map. Which concrete implementation of the Map interface should be used for the new instance?
TreeMap
HashMap
LinkedHashMap
The answer depends on the implementation of the existing instance.
Which interface does java.util.Hashtable implement?
What will be the output of the program?
public class RTExcept
{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}
hello throwit caught
Compilation fails
hello throwitRuntimeException caught after
hello throwit caught finally after
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
/* Missing Statement ? */
public class foo
{
public static void main(String[]args)throws Exception
{
java.io.PrintWriter out = new java.io.PrintWriter();
new java.io.OutputStreamWriter(System.out,true); out.println("Hello");
}
}
What line of code should replace the missing statement to make this program compile?
What is the numerical range of char?
0 to 32767
0 to 65535
-256 to 255
-32768 to 32767
Which of the following are Java reserved words?
1.run
2.import
3.default
4.implement
1 and 2
2 and 3
3 and 4
2 and 4
