NEW
Font size
WorksheetsTo meet the horizon
Total questions: 20
Worksheet time: 20mins
Which of the following option leads to the portability and security of Java?
Bytecode is executed by JVM
The applet makes the Java code secure and portable
Use of exception handling
Dynamic binding between objects
Which of the following is a valid long literal?
8097
L990023
904423
0xF029L
What does the expression float a = 0 / 0 return?
0
Not a Number
Infinity
Run time exception
What would be the result of attempting to compile and run the following code?
public class HelloWorld{
public static void main(String[] args){
double[] x = new double[]{1, 2, 3};
System.out.println("Value is " + x[1]);
}
}
The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}.
The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};
The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};
The program compiles and runs fine and the output.
Which will legally declare, construct, and initialize an array?
int [] myList = {};
int [] myList = (5, 8, 2);
int myList [] [] = {4,9,7,0};
int myList [] = {4, 3, 7};
Which is the correct way of knowing Array Size (int ary[]) in Java?
ary.length()
ary.length
ary->length()
ary->length
What is the output of the below Java program?
int balls[], rounds=3;
balls = new int[rounds];
for(int i=0; i<balls.length; i++)
balls[i] = (i+1)*2;
for(int j=0; j<balls.length; j++)
System.out.print(balls[j] + ",");
0,2,4,
1,2,3,
2,4,6,
Compiler error
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}
}
i = 10, j = 20
i = 20, j = 10
i = 10, j = 10
i = 20, j = 20
class Main {
public static void main(String args[]){
final int i;
i = 20;
i = 30;
System.out.println(i);
}
}
20
30
0
Error
Given the code :
void Star (Point P1, Point P2)
{
Point PM = new Point( ) ;
int P1 = T1.h + t1.m * 60 ;
int P2 = T2.h + t2.m*60 ;
int tm3 = (t1>t2) ? (t1-t2) : ( t2 – t1) ;
h = tm3/ 60 ;
m = tm3 % 60 ;
}
What is 'odd one out' in the code?
h and m not declared
P1 and P2 of no use
object PM unused
more than one statements odd
The expansion of P XOR Q is :
P’.Q + P’.Q’
P.Q + P’Q’
P’.Q + P.Q’
P.Q + P.Q’
The complement of P’.Q’ + P.Q’ will be
( (P+Q) . (P’ + Q) )’
( (P+Q) . (P + Q’) )’
( P+Q ) . (P’ + Q)
( P’+Q’ ) . (P + Q’)
If A=1, B=0, C=0 and D=0, then the maxterm will be:
A . B’ . C’ . D’
A’ + B + C + D
A + B’ + C’ + D’
A’ . B . C . D
If A = 0, B = 1, C = 1 and D = 0, then the minterm will be:
A’ . B . C . D’
A + B’ + C’ + D
A . B’ . C’ . D
A’ + B + C + D’
The expression A.B’ + A + B’.C will be:
A tautology
A contradiction
A contingency
Invalid expression
Given the code :
void gnSpeed ( )
{
int x = 5, y = 10, p = 18 ;
if ( p > y )
{
x = x + 10 ;
}
else if ( x > 10)
{
x = p + y ;
}
}
What will be the final value of x?
18
23
28
None of the above
Given the code :
void gnSpread ( )
{
int d = 1 , m = 10 , n = 9, p = 0 ;
if ( m > n )
{
p = 1;
}
if ( d = = 1 )
{
p = 2;
}
else
{
p = 3;
}
}
What will be the final value of p ?
1
2
3
None of the above
Given code, what will be the output:
int k = 4 , g = 6 ;
while ( k++ < g)
System.out.println ( “Yoko = “ + k *g ) ;
System.out.println (“Hama = “ + k *g ) ;
Yoko = 30
Hama = 36
Hama = 42
Yoko = 30
Yoko = 36
Hama = 42
Yoko = 25
Yoko = 30
Hama = 36
None of the above
Given the code :
void gnSpeed ( )
{
int x = 52 , y = 7651 , p = 18 ;
if ( p > y || y > x )
{
y = y % 100 ;
}
p = ( x > y ) ? (p+2) : (p-8) ;
}
What will be the final value of p ?
18
10
20
28
Given the code:
int d = 69 , p = 96 ;
do
{
System.out.print ( d + p ) ;
} while (d != p ) ;
The code is infinite
The code will never run
The code will run once
Error in the code
