menu

Java Basics

Java Basics - Important Points


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

A. int

B. boolean

C. double

D. string

Discuss Work Space

Answer: option b

Explanation:

Boolean is a wrapper class in Java that is used to represent a boolean value.

17. Which of the following is NOT a valid way to create a thread in Java?

A. Implementing the Runnable interface

B. Extending the Thread class

C. Calling the start() method on a Thread object

D. Creating a new instance of the Thread class

Discuss Work Space

Answer: option c

Explanation:

Calling the start() method on a Thread object is a valid way to start a thread in Java.

18.

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");
  }
 }
}

A. x is greater than y

B. x is less than or equal to y

C. Both statements are printed

D. No output

Discuss Work Space

Answer: option a

Explanation:

The condition x > y is true, so the output is "x is greater than y".


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

A. try

B. catch

C. finally

D. handle

Discuss Work Space

Answer: option d

Explanation:

Handle is not a valid exception handling keyword in Java.

20.

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);
 }
}

A. The sum of 10 and 5 is 15

B. The sum of x and y is z

C. The sum of x and y is 15

D. No output

Discuss Work Space

Answer: option a

Explanation:

The values of x, y, and z are used to create a string that is printed to the console.



Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now