File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -238,4 +238,33 @@ C. It does not have a default value.
238238D. It will not compile without initializing on the declaration line
239239```
240240B. 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```
You can’t perform that action at this time.
0 commit comments