menu

Java Basics


1.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 5;
int y = 2;
System.out.println(x / y);
 }
}

2

2.5

2

None of the above


2.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
System.out.println("Hello" + " World");
}

Hello

World

Hello World

HelloWorld


3. Which of the following is NOT a valid identifier in Java?

myVariable

$variable

2variable

_variable


4.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 10;
int y = 5;
System.out.println(x > y);
 }
}

1

0

1

0


5.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int[] numbers = {1, 2, 3};
System.out.println(numbers[1]);
 }
}

1

2

3

IndexOutOfBoundsException


6.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
for(int i = 0; i < 5; i++) {
System.out.println(i);
  }
 }
}

0 1 2 3 4

1 2 3 4 5

0 1 2 3 4 5

Infinite loop


7.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
String name = "Java";
for(int i = 0; i < name.length(); i++) {
System.out.print(name.charAt(i) + " ");
  }
 }
}

J a v a

Java

Jv

No output


8. Which of the following is NOT a valid exception handling keyword in Java?

try

catch

finally

handle


9. Which of the following is NOT a valid way to create a thread in Java?

Implementing the Runnable interface

Extending the Thread class

Calling the start() method on a Thread object

Creating a new instance of the Thread class


10. Which of the following is NOT a control statement in Java?

if

while

switch

string