aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes primitive assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "primitive assignment" Watch "primitive assignment" New topic
Author

primitive assignment

junming zhang
Greenhorn

Joined: Nov 03, 2001
Posts: 8
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!


Dream first and Do later
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 128
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.


Darryl Failla
Sun Certified Java 2 Programmer
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Agree with Daryl, only b is correct answer.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi all,
i'm also able to compile only B on jdk 1.3
regards,
maulin
junming zhang
Greenhorn

Joined: Nov 03, 2001
Posts: 8
best thanks for darryl,nain,maulin!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitive assignment