Java Basic Programs for Beginners
Java Basic Programs for Beginners - Important Points
| 26. | Which of the following is a valid way to declare a constant in Java? |
|---|
A. final int var = 5;
B. int const var = 5;
C. const int var = 5;
D. int var = 5; final
View Answer Discuss Work SpaceAnswer: option a
Explanation:
| 27. | What is the output of the following program? public class Main { |
|---|
A. 2.5
B. 2
C. 3
D. 5
View Answer Discuss Work SpaceAnswer: option b
Explanation:
| 28. | Which of the following is a valid way to declare and initialize a char variable in Java? |
|---|
A. char var = 'a';
B. char var = "a";
C. char var = 97;
D. char var = 'a'.toUpperCase();
View Answer Discuss Work SpaceAnswer: option a
Explanation:
| 29. | What is the output of the following program? public class Main { |
|---|
A. 1
B. 0
C. Compile error
D. Runtime error
View Answer Discuss Work SpaceAnswer: option b
Explanation:
| 30. | Which of the following is not a valid way to declare and initialize an integer array in Java? |
|---|
A. int[] arr = {1, 2, 3};
B. int[] arr = new int[]{1, 2, 3};
C. int[] arr = new int[3] {1, 2, 3};
D. int[] arr = new int[3]; arr[0] = 1; arr[1] = 2; arr[2] = 3;
View Answer Discuss Work SpaceAnswer: option c
Explanation: