aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes QUICK assignments exam q .. 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 "QUICK assignments exam q .." Watch "QUICK assignments exam q .." New topic
Author

QUICK assignments exam q ..

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232
Question 57.
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;
//I LIKE B ONLY, BUT ANSWER LIKES A AS WELL, HOW COME ?
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Sarim,
"B" is the only right anwer.
The thumb rule is -
Remember any other primitive other than a char, when assigned to char requires "EXPLICIT CASTING".
int i = 10;
char c = (char) i;
The above compiles fine.
HTH,
Aruna
sachin patel
Ranch Hand

Joined: Nov 28, 2000
Posts: 75
yes aruna is right it needs a explicit cast to convert from int to char.
------------------
Sachin,
**************************************************
Learn from others mistakes. Life is too short to make all yourself.
**************************************************


Sachin,<P>****************************************************<BR>Learn from others mistakes. Life is too short to make all yourself.<BR>****************************************************
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QUICK assignments exam q ..