menu

Java Basics


1.

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


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


3.

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


4.

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


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.

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


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


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

int

boolean

double

string


10.

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