aspose file tools
The moose likes Mock Exam Errata and the fly likes Marcus Green's Exam 2 #46 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Marcus Green Watch "Marcus Green New topic
Author

Marcus Green's Exam 2 #46

Ada Wang
Greenhorn

Joined: Aug 28, 2000
Posts: 23
Question 46)
Given the following variables which of the following lines will compile without error?
String s = "Hello";
long l = 99;
double d = 1.11;
int i = 1;
int j = 0;
1) j=i<<s;>
2) j=i<<j;>
3) j=i<<d;>
4) j=i<<l;>
I think 4) is incorrect. Before shifting, variable i is promoted to long since l is a long variable, but j is still int. The long result can't assign to a int variable j. Right? Please comment.
Ada
Sarada Bhasker
Ranch Hand

Joined: Sep 11, 2000
Posts: 94
In the case of shift operators only the left-hand operand data type is taken into account.
The right-hand operand is converted to a number less than 32 if left-hand operand in int
or less than 64 if the left-hand operand in long and the resultant data type is always
same as left-hand operand.
so your point would have been correct if it is l >> j and not j >> l.
 
IntelliJ Java IDE
 
subject: Marcus Green's Exam 2 #46
 
Threads others viewed
Bit shifting?
Shift & promotion
a question?
shifting
Marcus Q46
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com