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
View Answer Discuss Work SpaceAnswer: option c
Explanation:
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
View Answer Discuss Work SpaceAnswer: 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
View Answer Discuss Work SpaceAnswer: option c
Explanation:
9. | Which of the following is used to create an object in Java? |
---|
A. class
B. new
C. object
D. create
View Answer Discuss Work SpaceAnswer: option b
Explanation:
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
View Answer Discuss Work SpaceAnswer: option b
Explanation:
The index of an array starts from 0 in JavThe output is the value at index 1, which is 2.