menu

Java Basics


1. Which of the following is a wrapper class in Java?

int

boolean

double

string


2.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 10;
int y = 5;
if(x > y) {
System.out.println("x is greater than y");
} else {
System.out.println("x is less than or equal to y");
  }
 }
}

x is greater than y

x is less than or equal to y

Both statements are printed

No output


3.

What is Java?

A programming language

An operating system

A database management system

A web browser


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

myVariable

$variable

2variable

_variable


5.

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


6.

What is the output of the following code?

public class Test {
public static void main(String args[]) {
int x = 10;
int y = 5;
int z = x + y;
System.out.println("The sum of " + x + " and " + y + " is " + z);
 }
}

The sum of 10 and 5 is 15

The sum of x and y is z

The sum of x and y is 15

No output


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.

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


9.

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


10.

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