Skip to content

Commit 1fd71bc

Browse files
committed
Update java-multiple-choice-questions-answers.md
1 parent d663369 commit 1fd71bc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

java-multiple-choice-questions-answers.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,33 @@ C. It does not have a default value.
238238
D. It will not compile without initializing on the declaration line
239239
```
240240
B. It defaults to null.
241+
```
242+
#### Q. How many of the following methods compile?
243+
public class Test
244+
{
245+
public String convert(int value) {
246+
return value.toString();
247+
}
248+
public String convert(Integer value) {
249+
return value.toString();
250+
}
251+
public String convert(Object value) {
252+
return value.toString();
253+
}
254+
255+
public static void main(String... args) {
256+
Test obj = new Test();
257+
System.out.println(obj.convert(10));
258+
}
259+
}
260+
A. None
261+
B. One
262+
C. Two
263+
D. Three
264+
```
265+
C. Two
266+
267+
Explanation: Objects have instance methods while primitives do not. Since int is a primitive, you
268+
cannot call instance methods on it. Integer and String are both objects and have
269+
instance methods
241270
```

0 commit comments

Comments
 (0)