menu

Java Basics


1. Which of the following is NOT a valid type of inheritance in Java?

Single

Multiple

Hierarchical

Hybrid


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

int

boolean

double

string


3.

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


4.

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


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


6. Which of the following is a valid way to declare a variable in Java?

int x = 5;

int 5 = x;

x = 5;

int x;


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

public

private

protected

static


8.

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


9.

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


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

class

new

object

create