Review Questions with Verified
Solutions
Which of the following data types is used to store a single character in Java?
A) `String`
B) `int`
C) `char`
D) `boolean`
✔✔ Answer: C) char
What will be the result of the following code snippet?
```java
int a = 10;
int b = 3;
int result = a / b;
1
,System.out.println(result);
```
A) `3.33`
B) `3`
C) `10`
D) `0`
✔✔ Answer: B) 3
How do you declare an `ArrayList` of `Integer` objects in Java?
A) `ArrayList<Integer> list = new ArrayList<Integer>();`
B) `ArrayList list = new ArrayList<Integer>();`
C) `ArrayList<Integer> list = new ArrayList();`
D) `ArrayList<Integer> list = new List<Integer>();`
✔✔ Answer: A) ArrayList<Integer> list = new ArrayList<Integer>();
2
,Which method is used to add an element to the end of an `ArrayList`?
A) `add()`
B) `insert()`
C) `append()`
D) `push()`
✔✔ Answer: A) add()
What does the following code snippet do?
```java
String str = "hello";
System.out.println(str.substring(1, 4));
```
A) `hell`
3
, B) `ell`
C) `he`
D) `hello`
✔✔ Answer: B) ell
Which of the following operators is used to compare two values for equality in Java?
A) `==`
B) `=`
C) `!=`
D) `===`
✔✔ Answer: A) ==
What will be the output of this code?
```java
4