MAKAYAWA (PART 1) Flashcards
What is the correct way to declare a main method in Java?
A) public static void main(String[] args)
B) static void main(String args)
C) void main(String[] args)
D) public static main(String args)
A) public static void main(String[] args)
What will be the output of the following code?
System.out.println("Java" + 1 + 2);
A) Java3
B) Java12
C) Java 12
D) Error
B) Java12
Which of the following is a correct statement in Java?
A) int 1number = 5;
B) int number_1 = 5;
C) int #number = 5;
D) int number# = 5;
B) int number_1 = 5;
What will be the output of the following code?
System.out.println(10 + 20 + "Java" + 30 + 40);
A) 30Java70
B) 30Java3040
C) 1020Java3040
D) 1020Java70
B) 30Java3040
Which of the following is a single-line comment in Java?
A) /* comment */
B) <!– comment –>
C) // comment
D) # comment
C) // comment
What will the following code print?
// int x = 10;
int x = 5;
System.out.println(x);
A) 10
B) 5
C) Error
D) Nothing
B) 5
Which of the following is a correct way to declare a variable in Java?
A) int number = 5;
B) int 5number;
C) float = number;
D) double num = 2,5;
A) int number = 5;
What will be the output of the following code?
int a = 5;
int b = 10;
System.out.println("a = " + a + ", b = " + b);
A) a = 5, b = 10
B) a = 10, b = 5
C) Error
D) a = b, b = a
A) a = 5, b = 10
Which of the following is not a primitive data type in Java?
A) int
B) boolean
C) String
D) float
C) String
What will be the output of the following code?
boolean flag = true;
if(flag) {
System.out.println("True");
} else {
System.out.println("False");
}
A) True
B) False
C) Error
D) Nothing
A) True
Which of the following is the correct operator for equality checking in Java?
A) =
B) ==
C) ===
D) !=
B) ==
What will be the output of the following code?
int a = 5;
int b = 10;
int c = a + b * 2;
System.out.println(c);
A) 30
B) 25
C) 20
D) 15
B) 25
What is the correct syntax of an if-else statement in Java?
A) if (condition) { //code } else { //code }
B) if {condition} (//code) else { //code }
C) if (condition) //code else { //code }
D) if condition { //code } else { //code }
A) if (condition) { //code } else { //code }
What will be the output of the following code?
int x = 10;
if (x > 10) {
System.out.println("Greater");
} else {
System.out.println("Lesser or Equal");
}
A) Greater
B) Lesser or Equal
C) Error
D) Nothing
B) Lesser or Equal
What will be the output of the following code?
int day = 3;
String dayName;
switch (day) {
case 1:
dayName = “Sunday”;
break;
case 2:
dayName = “Monday”;
break;
case 3:
dayName = “Tuesday”;
break;
default:
dayName = “Unknown”;
}
System.out.println(dayName);
A) Sunday
B) Monday
C) Tuesday
D) Unknown
C) Tuesday
Which of the following cannot be used as a switch expression in Java?
A) int
B) String
C) boolean
D) char
C) boolean
What is the correct syntax of a for loop in Java?
A) for (initialization; condition; increment/decrement) { //code }
B) for (initialization; increment/decrement; condition) { //code }
C) for (condition; initialization; increment/decrement) { //code }
D) for (initialization; condition) { //code }
A) for (initialization; condition; increment/decrement) { //code }
What will be the output of the following code?
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 2; j++) {
System.out.println("i = " + i + ", j = " + j);
}
}
A) i = 0, j = 0
B) i = 0, j = 0 to i = 4, j = 1
C) i = 5, j = 2
D) Error
B) i = 0, j = 0 to i = 4, j = 1
What does the break statement do in a loop?
A) It skips the current iteration.
B) It exits the loop.
C) It restarts the loop.
D) It stops execution of the program.
B) It exits the loop.
What will be the output of the following code?
for (int i = 0; i < 5; i++) {
if (i == 3) {
break;
}
System.out.println(i);
}
A) 0 1 2
B) 0 1 2 3
C) 1 2 3
D) 0 1 2 3 4
A) 0 1 2
How do you declare an array in Java?
A) int[] arr;
B) arr[] int;
C) int arr[];
D) A and C
D) A and C
What will be the output of the following code?
int[] arr = {1, 2, 3, 4};
System.out.println(arr[2]);
A) 1
B) 2
C) 3
D) 4
C) 3
Which of the following correctly declares a 2D array in Java?
A) int[][] arr;
B) int arr[2][2];
C) int[] arr[];
D) A and C
D) A and C
What will be the output of the following code?
int[][] arr = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
System.out.println(arr[1][2]);
A) 5
B) 6
C) 7
D) 8
B) 6
Which method can be used to find the length of an array in Java?
A) length()
B) size()
C) getLength()
D) length
D) length