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


4.

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


5.

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


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

public

private

protected

static


7.

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


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


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

try

catch

finally

handle