menu

Java Basics


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

try

catch

finally

handle


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

myVariable

$variable

2variable

_variable


3.

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


4. Which of the following is NOT a valid way to create an object in Java?

MyClass object = new MyClass();

MyClass object = MyClass();

MyClass object;

MyClass object = null;


5.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
String name = "Java";
System.out.println(name.substring(1, 3));
 }
}

Ja

av

Jav

No output


6. Which of the following is NOT a loop in Java?

while

for

do-while

if


7.

What is Java?

A programming language

An operating system

A database management system

A web browser


8.

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


9.

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


10.

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