Given:
11. public static void main(String[] args) {
12. Integer i = uew Integer(1) + new Integer(2);
13. switch(i) {
14. case 3: System.out.println(”three”); break;
15. default: System.out.println(”other”); break;
16. }
17. }
‘What is the result?
1 three
2 other
3 An exception is thrown at runtime.
4 Compilation fails because of an error on
line 12.
Answers were Sorted based on User's Feedback
Answer / venkata krishna
Hi,
Answer is 1 means three..
line 12 is executing sucuessfully ,after that i is 3 now
line 13 is switch also executed successfully and print the
three
Is This Answer Correct ? | 8 Yes | 2 No |
In the line 12 .jus think new Integer(1) will result 1 and
new Integer(2) will result 2 so 1+2=3 which is stored in a i.
so the line 12 can b written as a Integer i=1+2;
the answer is 1) three
Is This Answer Correct ? | 5 Yes | 1 No |
In the line 12 .jus think new Integer(1) will result 1 and
new Integer(2) will result 2 so 1+2=3 which is stored in a i.
so the line 12 can b written as a Integer i=1+3;
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / kumar
The above scenario using Wrapper class.The Wrapper class
allows arthmetic opertion(Boxing and unboxing the interget
numbers).So the result will be "three"
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / nirmal
Ans 4: Compilation fails because of an error on
line 12.
Reason: The operator + is undefined for the argument type
(s) java.lang.Integer, java.lang.Integer Cannot switch on a
value of type Integer. Only int values or enum constants
are permitted.
Is This Answer Correct ? | 0 Yes | 4 No |
What happens when a class is made static like if a field or member is made static it becomes class variable and is shared by all the object of the class?
what Data encapsulation in java?
where singleton classes are used in j2ee web application.can we use it for connection pooling.
How do I print a “?
How do you convert an int to a string in java?
why did you choose your career in IT?
What is the difference between a scrollbar and a scrollpane?
What is the purpose of file class?
I have a String s = java; What is the output when I say s.replaceAll('j', 'k'); Also what is the value of s after replacing?
Is passing by reference faster?
What are the java ide’s?
How do you differentiate abstract class from interface?