MAKAYAWA (PART 1) Flashcards

1
Q

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

A) public static void main(String[] args)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What will be the output of the following code?
System.out.println("Java" + 1 + 2);

A) Java3
B) Java12
C) Java 12
D) Error

A

B) Java12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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;

A

B) int number_1 = 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

B) 30Java3040

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following is a single-line comment in Java?

A) /* comment */
B) <!– comment –>
C) // comment
D) # comment

A

C) // comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What will the following code print?
// int x = 10;
int x = 5;
System.out.println(x);

A) 10
B) 5
C) Error
D) Nothing

A

B) 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A) int number = 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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) a = 5, b = 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is not a primitive data type in Java?

A) int
B) boolean
C) String
D) float

A

C) String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A) True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is the correct operator for equality checking in Java?

A) =
B) ==
C) ===
D) !=

A

B) ==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

B) 25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A) if (condition) { //code } else { //code }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

B) Lesser or Equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

C) Tuesday

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of the following cannot be used as a switch expression in Java?

A) int
B) String
C) boolean
D) char

A

C) boolean

15
Q

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

A) for (initialization; condition; increment/decrement) { //code }

16
Q

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

A

B) i = 0, j = 0 to i = 4, j = 1

16
Q

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.

A

B) It exits the loop.

16
Q

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

16
Q

How do you declare an array in Java?

A) int[] arr;
B) arr[] int;
C) int arr[];
D) A and C

A

D) A and C

17
Q

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

18
Q

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

A

D) A and C

19
Q

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

20
Q

Which method can be used to find the length of an array in Java?

A) length()
B) size()
C) getLength()
D) length