JAVA QUIZ 14

0
Created on By Sirjana GhimireAcharya

JAVA QUIZ 14

1 / 10

1.Which class has defined the equals(Object o) method?

2 / 10

2.What will happen when you compile and run the following code?

public class Test{
static int i;
public static void main(String[] args) {
Test t = null;
System.out.println(t.i);
}
}

3 / 10

3. What will happen when you compile and run the following code?

class One{
public One(){
System.out.print("One");
}
}

class Two{
public Two(){
System.out.print("Two");
}
}

class Three{
public Three(){
System.out.print("Three");
}
}
public class Test{

static Three three = new Three();
Two two = new Two();
static One one = new One();

public static void main(String[] args) {
System.out.print("Hello");
Test t = new Test();
}
}

4 / 10

4.What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){
int a = 0;
while(a + 2 < 10){
a += 2;
int b = 10;
while(b - 2 > 0){
b -= 2;
}
}
System.out.println(a + " " + b);
}

}

5 / 10

5.What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args){

int i = 97;

switch(i){
case 95 :
System.out.print("95");
case 96 :
System.out.print("96");
case 'a' :
System.out.print("a");
case 'b' :
System.out.print("b");
case 'c' :
System.out.print("c");
}
}
}

6 / 10

6. What will happen when you compile and run the following code?

public class Test{

public static void main(String[] args) {
int i = 10 + 011 + 12;
System.out.println(i);
}
}

7 / 10

7. A constructor cannot throw any exception. It must handle all the exception itself using try catch block.

8 / 10

8.A constructor can be synchronized.

9 / 10

9.An interface cannot define an inner class.

10 / 10

10. What will happen when you compile and run the following code?

public class Test{

static String time = getTime();
static String currentTime = "5:30";

private static String getTime() {
return currentTime;
}

public static void main(String[] args) {
System.out.println(time);
}
}

Your score is

The average score is 0%

0%