JAVA

Welcome to your Java MCQ Test

1. 
What is the result of 10 + 20 + "Java" in Java?

2. 
What will be the output of following Java code?

import java.util.Scanner;

class ThisKeyword {
private int a = 4;
private int b = 1;

void getSum(int a, int b) {
this.a = a;
this.b = b;
System.out.println(this.a + this.b);
}
}

public class Main {
public static void main(String args[]) {
ThisKeyword T = new ThisKeyword();
T.getSum(3, 5);
}
}

3. 
What is stringBuffer in java?

4. 
What is file handling in java?

5. 
Which of the following is a superclass of every class in Java?

6. 
What will be the output of following Java code?

public class Main {
public static void main(String arg[]) {
int i;
for (i = 1; i <= 12; i += 2) {
if (i == 8) {
System.out.println(i);
break;
}
}
}
}

7. 
Which of these is the correct method to create an array in java?

8. 
Object in java are ___.

9. 
Which method in java is used to generate random numbers in Java?

10. 
What is the default value of a boolean variable in Java?

11. 
How can we access methods for file handling in java?

12. 
Can the Java program accept input from the command line?

13. 
Static variables in java are declared as ___.

14. 
Which of the following can be declared as final in java?

15. 
What will be the output of following Java code?

public class Main {
public static void main(String[] args) {
String str = "Hello";
str = "Bye";
System.out.println(str);
}
}

16. 
What will be the output of following Java code?

import java.util.Scanner;

class ThisKeyword {
private int a = 4;
private int b = 1;

void getSum(int a, int b) {
this.a = a;
this.b = b;
System.out.println(this.a + this.b);
}
}

public class Main {
public static void main(String args[]) {
ThisKeyword T = new ThisKeyword();
T.getSum(3, 5);
}
}

17. 
Which keyword in java is used for exception handling?

18. 
Can we keep a different name for the java class name and java file name?

19. 
Which method can be used to find the length of a string in Java?

20. 
Which method deletes a file in Java?