Integer Group Literals addition
What will be the output of the following program?
class AddIntegerGroup
{
public static void main(String s[])
{
byte b = 13;
short s = 0313;
int i = 230313;
long l = b + s + i;
System.out.println("l = " + l);
}
}
A.
|
l = 673313
|
B.
|
l = 230639
|
C.
|
l = 230529
|
D.
|
Compilation Error
|
Topic:
Type Conversion In Java
If you need explanation Read this topic
If you need Answer Take test on this topic
User comments below. All of them might not be correct.
b.type conversion occurs n the values of dfent dta typ r added n get the result in long.
Posted by Asma Mujtaba Khan 2014-08-12 03:57:13
c.wen int i n short s are added ans is 230516 due to type conversion n range of short ..wen thid reslt is added to byte b..the resullt is 230529
Posted by Wajahat Khan 2014-08-12 04:12:12
c.wen int i n short s are added ans is 230516 due to type conversion n range of short ..wen thid reslt is added to byte b..the resullt is 230529
Posted by Wajahat Khan 2014-08-12 04:12:16
c..here short s=0313 is wen compile is equivalent to 203...hence wen 13+203+230313 r added the result is 230529
Posted by Bilal Ahmad 2014-08-12 04:16:59
Ans C:here b=13 and s=203 (short 0313 value is 203,i=230313...so l=13+203+230313 is 230529...
Posted by Ashok Reddi 2014-08-12 07:25:38
No winner for this dose. Correct option is 'D' :( why because "Duplicate local variable s" at line 6 it causes compilation error.
Posted by Merit Campus 2014-08-13 04:23:54