menu

Java Basics

Java Basics - Important Points


6. Which of the following is a loop statement in Java?

A. if

B. switch

C. for

D. try

Discuss Work Space

Answer: option c

Explanation:

The 'for' statement is a loop statement in Java that is used to execute a block of code repeatedly.

7.

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

A. 1

B. 0

C. 1

D. 0

Discuss Work Space

Answer: option a

Explanation:

The comparison operator '>' returns a boolean value. In this case, it is true because x is greater than y.


8. Which of the following is NOT a valid identifier in Java?

A. myVariable

B. $variable

C. 2variable

D. _variable

Discuss Work Space

Answer: option c

Explanation:

A variable name cannot start with a number in JavThe other options are valid identifiers.

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

A. class

B. new

C. object

D. create

Discuss Work Space

Answer: option b

Explanation:

The 'new' keyword is used to create an object of a class in Java.

10.

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

A. 1

B. 2

C. 3

D. IndexOutOfBoundsException

Discuss Work Space

Answer: option b

Explanation:

The index of an array starts from 0 in JavThe output is the value at index 1, which is 2.



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