Font size
WorksheetsJAVA TEST for BATCH J6_J8
Total questions: 100
Worksheet time: 2hrs 24mins
Predict the output:
"Hello Abstract World"
compile time error
runtime exception
None of the above
Predict the output:
[PJP, Java]
[Python, PJP, Java]
[PJP, Java]
Compile time error
Run time error
None of the above
Predict the output:
Prints nothing
Compile Time Error: variable x is already defined
9
8
Predict the output:
Run command is issued as: Java Sample "Hello World"
"Hello World"
"Hello
Hello
Hello World
Predict the output:
Prints nothing
0
null
OutOfBoundsException
Predict the output:
Child display..
Child display..Parent display..
Parent display..Child display..
Compile Time Error
Predict the output:
true false
true true
false true
false false
Predict the output:
There is no reverse() available for StringBuffer
emocleW yajA
Ajay Welcome
yajA emocleW
Predict the output:
a = 0
Divide by zero error
a = 0
inside the finally block
a = 0
Divide by zero error
inside the finally block
Divide by zero error
inside the finally block
Which of the below is/are valid identifier with the main method?
public
private
static
this
What is the extension of java code files?
.class
.txt
.java
.js
class KIET_Test {
int x;
}
class Main {
public static void main(String args[]) {
KIET_Test t = new KIET_Test();
System.out.println(t.x);
}
}
garbage value
0
compiler error
runtime error
Which of the following is a valid declaration of an object of class Box?
Box obj = new Box;
Box obj = new Box();
obj = new Box();
new Box obj;
Which of these operators is used to allocate memory for an object?
malloc
alloc
new
this
What is the output of the below Java code snippet?
char ch = 'A';//ASCII 65
int a = ch + 1;
ch = (char)a;
System.out.println(ch);
A) 66
B) A
C) B
D) 65
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
Find the output for the following.
public class IncDec
{
public static void main(String s[])
{
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
System.out.println("a = " + a);
System.out.print("b = " + b);
System.out.println("c = " + c);
System.out.print("d = " + d);
}
}
a = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
What will be the output?
24
32
23
31
________ keyword is used to monitor an exception.
try
catch
throw
throws
class increment {
public static void main(String args[]) {
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4); } }
1 1
0 1.5
1.5 1
1 1.5
class increment {
public static void main(String args[]) {
int g = 3;
System.out.print(++g * 8); } }
24
32
25
34
class Output {
public static void main(String args[]) {
int a = 1; int b = 2; int c; int d;
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c); } }
4 4 3
3 3 4
3 4 4
4 3 3
class bitwise_operator {
public static void main(String args[]) {
int var1 = 42;
int var2 = ~var1;
System.out.print(var1 + " " + var2); } }
42 42
42 -43
43 42
43 -42
class bitwise_operator {
public static void main(String args[]) {
int a = 3;
int b = 6;
int c = a | b;
int d = a & b;
System.out.println(c + " " + d); } }
7 2
7 5
5 7
7 7
class rightshift_operator {
public static void main(String args[]) {
int x; x = 10;
x = x >> 1;
System.out.println(x); } }
2
7
5
10
What is Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of these interface declares core method that all collections will have?
Collection
EventListner
Comparator
Set
List
What implementation of Iterator can traverse a collection in both directions?
Iterator
ListIterator
SetIterator
MapIterator
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
The default capacity of a Vector is:
10
12
8
0
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
Which of these is synchronized?
TreeMap
HashMap
Hashtable
All of the above
How can you sort given HashMap on basis of values
Implement Comparator interface and override its compare method
It is not possible
Implement Comparator interface and override its compareTo method
Implement Comparator interface and override its comparable method
-Entries are organized as key/value pairs.
-Duplicate entries replace old entries.
-Entries are sorted using a Comparator or the Comparable interface.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
SortedSet
SortedMap
-Entries are not organized as key/value pairs.
-Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
None of the above
-Entries are not organized as key/value pairs.
-Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
None of the above
[Computer, Network, Networks, Programming, Security]
[Computer, Programming, Network, Networks, Programming, Security]
[Computer, Programming, Computer, Networks, Network, Security]
[Computer, Networks, Network, Programming, Security]
Which of the following is/are correct statements?
HashSet class implements the Set interface
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.
HashSet permits to have a single null value.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap and HashSet are threadsafe
Which of the following statement(s) is/are TRUE?
Both HashMap and HashSet are not synchronized.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap permits single null key and any number of null values.
Both HashMap and HashSet are synchronized.
{"Computer", "Programming","Networks","null"}
{"Computer", "Programming","Networks",null,"null"}
Line 11 : Genetates NullPointer Exception
Line12: Generates NullPointerException
List listNames = new ArrayList();
listNames.add("Tom");
listNames.add("Mary");
listNames.add("Peter");
String name2 = (String) listNames.get(1);
System.out.println(name2);
What is the output of the above code
Tom
Mary
Peter
raises Exception
int x = 5;
int y = 6
int z = 50;
System.out.println(x + y + z);
What will be the output?
61
5650
66
x + y + z
Which of the following is the right way of defining char variable?
char myGrade = 'B';
char myGrade = "B";
char myGrade 'B';
char myGrade = "B"
x /= 3
Which of the below statements matches with above statement?
x = 3 / x
x = x / 3
x / 3
x /x = 3
int x = 4;
System.out.println(x < 5 && x < 10);
What will be the output?
false
true
4
x < 5 && x < 10
What is the output of below code?
int x = 5;
System.out.println(x++);
System.out.println(x);
5
5
6
6
5
6
6
5
Command to run a Java program
javaa
java
jaava
jaavaa
java compiler converts the java file into _________ file.
.jvm
.class
.obj
.java
Which of these are selection statements in Java?
if()
for
continue
break
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
for
while
do..while
None of the above
Which of these is the correct format for an "if/else" statement?
Which of these is the proper format of an "else/if" chain statement?
What will the output of the following code segment be?
int a = 1, b = 2;
System.out.println(++a+”,”+b++);
1,2
2,2
2,3
3,3
What is each repetition of a loop known as?
cycle
revlolution
orbit
iteration
This statement causes a loop to terminate early.
a. continue
b. break
c. switch
d. none of the above
Base on the code block below what will be the output to the console?
int number =11;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will print to the console?
var n =5;
for(int i=1;i<=n;i++){
System.out.println(i);
}
1
2
3
4
5
5
4
3
2
1
1
2
3
4
4
3
2
1
Which one of these control flow statements does not loop
switch
while
do-while
for
Base on the code block below what will be the output to the console?
int number =2;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will be the output to the console?
int number =8;
if(number >=10) {
System.out.print("New York");
}
else if(number<=5){
System.out.print("California");
}
else System.out.print("Texas");
New York
California
Texas
Nothing
Base on the code block below what will print to the console?
var n =5;
for(int i=1;i<n;i++){
System.out.println(i);
}
1
2
3
4
5
5
4
3
2
1
1
2
3
4
4
3
2
1
Base on the code block below what will be the output to the console?
int n=5;
int c=0;
while(n>=0&&c<=5) {
System.out.println(c+":"+n);
c++;
n--;
}
1:1
2:2
3:3
4:4
5:5
1:4
2:3
3:2
4:1
0:5
1:4
2:3
3:2
4:1
5:0
0:0
1:1
2:2
3:3
4:4
5:5
How do you write a Greater than or equal to Relational operator
<=
=<
>=
=>
How do you write a Not equal to Relational operator
!=
=!
!==
!!=
How do you write am Equal to Relational operator
===
EQUAL
=
==
What is the output of the below Java program?
int hours = 10;
String message=null;
switch(hours)
{
case 10: message ="TEN"; break;
case 11: message ="TEN AGAIN"; break;
default: message ="TEN AS USUAL";
}
System.out.println(message);
TEN
TEN AGAIN
TEN AS USUAL
What is the output of the below Java program?
int hours = 10;
String message=null;
switch(hours)
{
case 10: message ="TEN";
case 11: message ="TEN AGAIN"; break;
default: message ="TEN AS USUAL";
}
System.out.println(message);
TEN
TEN AGAIN
TEN AS USUAL
What is the output of the below Java program?
int hours = 10;
String message=null;
switch(hours)
{
case 10: message ="TEN";
case 11: message ="TEN AGAIN";
default: message ="TEN AS USUAL";
}
System.out.println(message);
TEN
TEN AGAIN
TEN AS USUAL
What will be outputted from this code?
50
60
40
85
Which of the following use the correct syntax for a traditional for loop?
for(x=0; x<10; x++) {System.out.println(x);}
for(int x=0; x<10; x++) {System.out.println(x);}
for(x=0, x<10, x++){System.out.println(x);}
for(int x=0: x<10: x++){System.out.println(x);}
Which of the following use the correct syntax for an enhanced for loop?
for(int x=0; x<10; x++) {System.out.println(x);}
for(int x : numbers) {System.out.println(x);}
for(x=0, x<10, x++){System.out.println(x);}
for(int x=0: int numbers=10){System.out.println(x);}
Base on the code block below what will print to the console?
String Days[]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
for(int i=6;i>=0;i--) {
System.out.println(Days[i] );
}
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
Saturday
Friday
Thursday
Wednesday
Tuesday
Monday
Sunday
What would be outputted if you inputted "a"?
1
2
3
What would be outputted if you inputted "B"?
1
2
3
What would be outputted if you inputted "3"?
1
2
3
nothing, this will trigger an error.
What would print if the following code was inserted on line 9.
System.out.print(num1);
5
10
15
nothing, this will trigger a error.
What would print if the following code was inserted on line 13.
System.out.print(num3);
5
10
15
nothing, this will trigger an error.
Which three statements are jump statements?
case
default
continue
break
return
Which two statements are not jump statements?
case
default
continue
break
return
What will be outputted from this code?
5
6
nothing, this will trigger an error.
10
What is the output of this program?
0
2
6
8
10
0
2
4
2
4
Nothing, this program will not compile.
