menu

Java Basics


1.

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


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[]) {
System.out.println("Hello" + " World");
}

Hello

World

Hello World

HelloWorld


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

while

for

do-while

if


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

class

new

object

create


6.

What is the output of the following code?

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

4

5

6

7


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

public

private

protected

static


8. Which of the following is NOT a primitive data type in Java?

int

boolean

double

string


9.

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


10.

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