What will happen if you try to compile and run the following code?
------
public class MyClass {
public int x = 10;
public static int y = 10;
public static void main(String []args){
System.out.println(x==y);
}
}
1/10
public class MyClass {
public int x = 10;
public static int y = 10;
public static void main(String []args){
System.out.println(x==y);
}
}
Choose one
true
false
compilation error
runtime error
What will happen if you try to compile and run the following code?
------
public class MyClass {
public static void main(String []args){
byte a = 10;
byte b = 12;
byte c = a + b;
System.out.println(c);
}
}
2/10
public class MyClass {
public static void main(String []args){
byte a = 10;
byte b = 12;
byte c = a + b;
System.out.println(c);
}
}
Choose one
22
Compilation Error
Runtime Error
What will happen if you try to compile and run the following code?
------
public class MyClass {
public static void main(String []args){
byte a = 10;
int b = 12;
b+=a;
System.out.println(b);
}
}
3/10
public class MyClass {
public static void main(String []args){
byte a = 10;
int b = 12;
b+=a;
System.out.println(b);
}
}
Choose one
Compilation Error
Runtime Error
10
12
22
What will happen if you try to compile and run the following code?
------
public class MyClass {
public static void main(String []args){
boolean a = true;
boolean b = false;
if(b = a){
System.out.println(a+":"+b);
}
}
}
4/10
public class MyClass {
public static void main(String []args){
boolean a = true;
boolean b = false;
if(b = a){
System.out.println(a+":"+b);
}
}
}
Choose one
true:false
true:true
false:true
false:false
Compilation Error
Runtime Error
What will happen if you try to compile and run the following code?
------
public class MyClass {
public static void main(String []args){
boolean a = "true".toBoolean();
boolean b = false;
boolean c = a || b;
System.out.println(c);
}
}
5/10
public class MyClass {
public static void main(String []args){
boolean a = "true".toBoolean();
boolean b = false;
boolean c = a || b;
System.out.println(c);
}
}
Choose one
true
false
Compilation Error
Runtime Error
Which of the following statements are correct about "myFunction"?
------
public static void myFunction(String []args){
boolean []a = new boolean [0];
boolean []b = new Boolean [0];
boolean []c = new int [0];
int []d = new boolean[0];
}
6/10
public static void myFunction(String []args){
boolean []a = new boolean [0];
boolean []b = new Boolean [0];
boolean []c = new int [0];
int []d = new boolean[0];
}
Choose all that apply
The code will compile and execute successfully.
You cannot create a 0 length array.
You cannot assign an array of Boolean objects to an array of boolean primitives.
You cannot assign an array of integers to an array of boolean primitives.
The code will compile successfully but will generate an exception at execution.
What will be displayed when the following code is compiled and executed?
------
int i , j = 12;
System.out.println("i="+i);
System.out.println("j="+j);
7/10
int i , j = 12;
System.out.println("i="+i);
System.out.println("j="+j);
Choose one
i=12
j=12
1=0
j=12
i=null
j=12
Compilation Error
Execution Error
What will be displayed after the following code is compiled and executed?
------
String colour = "WHIte";
switch (colour) {
case "white":
System.out.println("white");
case "WHITE":
System.out.println("WHITE");
case "WhitE":
System.out.println("WhitE");
default:
System.out.println("default");
}
8/10
String colour = "WHIte";
switch (colour) {
case "white":
System.out.println("white");
case "WHITE":
System.out.println("WHITE");
case "WhitE":
System.out.println("WhitE");
default:
System.out.println("default");
}
Choose one
white
WHITE
WhitE
default
Compilation Error
Runtime Error
What will be displayed after the following code is compiled and executed?
------
long x = 3;
switch (x) {
case 3:
System.out.println(3);
case 2:
System.out.println(2);
case 1:
System.out.println(1);
break;
default:
System.out.println("default");
}
9/10
long x = 3;
switch (x) {
case 3:
System.out.println(3);
case 2:
System.out.println(2);
case 1:
System.out.println(1);
break;
default:
System.out.println("default");
}
Choose one
3
2
1
default
Compilation Error
Runtime Error
What will happen if you try to compile and run the following code?
------
int x = 3;
switch (x) {
default:
System.out.print("default");
case 3:
System.out.print(3);
case 2:
System.out.print(2);
case 1:
System.out.print(1);
}
10/10
int x = 3;
switch (x) {
default:
System.out.print("default");
case 3:
System.out.print(3);
case 2:
System.out.print(2);
case 1:
System.out.print(1);
}