menu

Java Basics


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

try

catch

finally

handle


2.

What is the output of the following code?

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

1

0

1

0


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

if

while

switch

string


4. Which of the following is used to create an object in Java?

class

new

object

create


5.

What is the output of the following program?

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

10

11

9

None of the above


6.

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


7. 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


8. Which of the following is a loop statement in Java?

if

switch

for

try


9. Which of the following is NOT a valid access modifier in Java?

public

private

protected

static


10.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 10;
if(x > 5 && x < 15) {
System.out.println("x is between 5 and 15");
} else {
System.out.println("x is not between 5 and 15");
  }
 }
}

x is between 5 and 15

x is not between 5 and 15

5 and 15

No output