NEW
Font size
WorksheetsJavaDemo1
Total questions: 15
Worksheet time: 8mins
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 valid keyword in java?
interface
string
Float
unsigned
Which is a valid declarations of a String?
String s2 = 'null';
String s1 = null;
String s3 = (String) 'abc';
String s4 = (String) '\ufeed';
What is the output of the following code:
class Test {
public static void main(String[] args) {
for(int i = 0; 1; i++) {
System.out.println("Hello");
break;
}
}
}
Prints Hello once
Prints Hello infinite times
Prints nothing
Compiler error
What is the output of the following code?
class Test {
public static void main(String[] args) {
for(int i = 0; 1; i++) {
System.out.println("Hello");
break;
}
}
}
0
20
Compiler Error
Prints Nothing
What is the output of the following code?
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler error
None of these
What will be the output of the following?
class Main{public static void main (String[] args) {
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
}};
finished
Compilation error
Exception
Arithmetic exception
What is the output of the following code?
class Main{public static void main (String[] args) {
try
{
int x = 0;
int y = 5 / x;
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
catch (Exception e)
{
System.out.println("Exception");
}
System.out.println("finished");
}
};
Exception
finished
Arithmetic Exception
finished
Compiler error
finished
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
What package is a part of the wrapper class which is imported by default into all Java programs?
java.awt
Which of these is not a method in the Collection interface?
add()
get()
remove()
size()
In which collection are elements stored as key-value pairs?
List
Set
Map
Queue
Which collection provides a guaranteed constant time for basic operations like add, remove, and contains?
What is the output of the following?
public class Main
{
public static void main(String [] args)
{
String s = "42";
try
{
s = s.concat(".5");
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");
}
}
}
42
43
42.5
bad number
Which of the following is true about interfaces in java?
1.An interface can contain following type of members:public, static, final fields (i.e., constants) ,default and static methods with bodies
2.An instance of interface can be created.
3.A class can implement multiple interfaces.
4.Many classes can implement the same interface.
1,3,4
1,2,4
2,3,4
1,2,3,4
