Professional Documents
Culture Documents
Java MCQ Worksheet-10 MCQ
Java MCQ Worksheet-10 MCQ
WORKSHEET-10
CORE CONCEPTS IN JAVA
class Main { ( )
public static void main(String args[]) {
int t;
System.out.println(t);
}
}
a. 0 b. garbage value c. compile error d. Runtime
error
2. class Test { ( )
for(int i = 0; 0; i++)
System.out.println("Hello");
break;
} }}
(1) Constants that cannot be changed are declared using the ‘static’ keyword.
(2) A class can only inherit one class but can implement multiple interfaces.
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
a. Compile error b.20 c. 0 d. garbage value
5. Output of the following program ( )
6. class Test { ( )
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
static int fun(int x = 0)
{
return x;
}
}
a. 0 b. garbage value c. compile error d. runtime error
class Test {
public static void main(String args[]) {
int x = -4;
System.out.print(x>>1+ “ “);
int y = 4;
System.out.println(y>>1);
}
}
11. Predict the output of following Java program. Assume that int is stored using 32 bits.( )
class Test {
public static void main(String args[]) {
int x = -1;
System.out.println(x>>>29+” “);
System.out.println(x>>>30+” “);
System.out.println(x>>>31);
}
}
a. 15 7 3 b. 0 0 0 c.1 1 1 d. 7 3 1
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. 8 2 b. 8 3 c.8 5 d.5 3
16. In Java, after executing the following code what are the values of x, y and z? int x,y=10;
z=12; x=y++ + z++; ( )
a. 4 16 b. 4 10 16 c. 0 6 12 18 d. 1 4 7 10 13 16 19
19. Which of the following loops will execute the body of loop even when condition controlling
the loop is initially fal ( )
a. do-while b).while c. for d. none of the mentioned
1. class selection_statements
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. if ((var2 = 1) == var1)
8. System.out.print(var2);
9. else
10. System.out.print(++var2);
11. }
12. }
a.1 b.2 c.3 d.4