aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sorry for the misprint of my previous question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Sorry for the misprint of my previous question" Watch "Sorry for the misprint of my previous question" New topic
Author

Sorry for the misprint of my previous question

Sangi
Greenhorn

Joined: Jun 14, 2000
Posts: 3
He is the question again,
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;
The correct answer is 2 & 4.I thought that it was only 2.Can anyone explain why it 4 too?Does'nt it apply arithmetic promtion here?Please help me.
Thanks
Sangi

[This message has been edited by Jim Yingst (edited June 15, 2000).]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
No, normal aritmetic promotion does not apply to the shift operators. They have their own rules, which are given here:
<blockquote>Binary numeric promotion (�5.6.2) is not performed on the operands; rather, unary numeric promotion (�5.6.1) is performed on each operand separately. The type of the shift expression is the promoted type of the left-hand operand.</blockquote>

"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorry for the misprint of my previous question
 
Similar Threads
Marcus Green's Exam 2 #46
Shift & promotion
Marcus Q46
Marcus Exam2 #46
a question?