• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Marcus Green's Exam 2 #46

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yup, yup, yup. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic