Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primitive assignment

 
junming zhang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q.......
Select the valid primitive assignments of the following.
A.int i = 10;
char c = i;
B.float f;
long l = 100L;
f = l;
C.short s = 20;
char c = s;
D.byte b = 20;
char c = b;
E.short s1 = 10;
short s2 = 20;
short result = s1*s2;
give answer is a & b.
but i can't compile both in jdk1.3.1,i think the cast is necessary!!
if i am wrong ,pls correct me!!thanks!

 
Darryl Failla
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code in a should not compile. You can't put a non-final int into a char without casting. To me, the only answer should be b.
 
Nain Hwu
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Daryl, only b is correct answer.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i'm also able to compile only B on jdk 1.3
regards,
maulin
 
junming zhang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
best thanks for darryl,nain,maulin!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic