MAKAYAWA (PART 3) Flashcards

1
Q

What is the result of the following code?
String s1 = "Hello";
String s2 = "World";
String s3 = s1.concat(s2);
System.out.println(s3);

A) Hello World
B) Hello
C) World
D) HelloWorld

A

D) HelloWorld

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

Which method is used to find the length of a string in Java?
A) length()
B) size()
C) getSize()
D) getLength()

A

A) length()

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

What will be the output of the following code?
String str = "Java Programming";
System.out.println(str.substring(5, 8));
A) Pro
B) Programming
C) gra
D) v

A

A) Pro

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

Which of the following is the correct way to create a Scanner object to read input from
the keyboard?

A) Scanner input = new Scanner(System.in);
B) Scanner input = new Scanner(System.out);
C) Scanner input = new Scanner(System.input);
D) Scanner input = new Scanner(System.key);

A

A) Scanner input = new Scanner(System.in);

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

What will be the output of the following code if the user inputs 25?
Scanner input = new Scanner(System.in);
int num = input.nextInt();
System.out.println("You entered: " + num);

A) You entered: 25
B) 25
C) Error
D) You entered: num

A

A) You entered: 25

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

What method is used to read a string input in Java using the Scanner class?

A) next()
B) nextLine()
C) getInput()
D) input()

A

B) nextLine()

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

What is the correct way to write an array declaration and initialization in Java?

A) int arr[] = {1, 2, 3};
B) int[] arr = {1, 2, 3};
C) int arr = [1, 2, 3];
D) A and B

A

D) A and B

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

Which of the following statements is incorrect in Java?
A) int x = 10;
B) String s = Hello;
C) float f = 3.14;
D) boolean b = “true”;

A

D) boolean b = “true”;

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

Which of the following options correctly fills in the blank to declare a variable?
int (blank)_= 10;

A) number
B) int
C) main
D) class

A

A) number

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?
System.out.println(10 / 3);

A) 3.3333
B) 3
C) 3.0
D) Error

A

B) 3

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 x = 5;
x++;
System.out.println(x);
A) 4
B) 5
C) 6
D) Error

A

C) 6

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

What is the output of the following code?
int a = 10;
a = a + 5;
System.out.println(a);

A) 10
B) 15
C) 20
D) 5

A

B) 15

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

Which of the following is a valid variable declaration in Java?

A) int 123abc;
B) int abc123;
C) int _abc;
D) B and C

A

D) B and C

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

Which data type can hold a single character in Java?

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

A

B) char

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

What is the size of the int data type in Java?

A) 8 bits
B) 16 bits
C) 32 bits
D) 64 bits

A

C) 32 bits

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

What will be the output of the following code?
int x = 20;
if (x == 20) {
System.out.println("Equal");
} else {
System.out.println("Not Equal");
}

A) Equal
B) Not Equal
C) Error
D) Nothing

15
Q

What will be the output of the following code?
int x = 10;
int y = x++;
System.out.println(y);

A) 9
B) 10
C) 11
D) Error

16
Q

Which of the following is the correct way to compare two strings in Java?
A) str1 == str2
B) str1.equals(str2)
C) str1.compareTo(str2)
D) str1 = str2

A

B) str1.equals(str2)

17
Q

What will be the output of the following code?
int number = 5;
switch (number) {
case 1:
System.out.println("One");
break;
case 5:
System.out.println("Five");
break;
default:
System.out.println("Unknown");
}

A) One
B) Five
C) Unknown
D) Error

18
Q

What is the return type of a method that does not return any value?
A) void
B) null
C) int
D) float

18
Q

What will be the output of the following code?
int i = 0;
while (i < 3) {
System.out.println(i);
i++;
}

A) 0 1 2
B) 1 2 3
C) 0 1 2 3
D) Error

19
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) 0 1 2 3 4
D) Error

20
Q

What will be the output of the following code?
int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr[2]);

A) 1
B) 2
C) 3
D) Error

21
Q

What will be the output of the following code?
public static void main(String[] args) {
System.out.println(add(5, 10));
}
static int add(int a, int b) {
return a + b;
}
A) 5
B) 10
C) 15
D) Error

22
Q

Which of the following allows a class to have more than one form?
A) Inheritance
B) Polymorphism
C) Abstraction
D) Encapsulation

A

B) Polymorphism