Question
public class Test
{
public static void leftshift(int i, int j)
{
i
What will be the output of the program?
public class Test
{
public static void leftshift(int i, int j)
{
i
Answer: Option B
Was this answer helpful ?
Java only ever passes arguments to a method by value (i.e. a copy of the variable)
and never by reference. Therefore the value of the variable i remains unchanged in
the main method.
If you are clever you will spot that 16 is 4 multiplied by 2 twice, (4 * 2 * 2) = 16. If you
had 16 left shifted by three bits then 16 * 2 * 2 * 2 = 128. If you had 128 right shifted by
2 bits then 128 / 2 / 2 = 32. Keeping these points in mind, you don't have to go converting
to binary to do the left and right bit shifts.
Was this answer helpful ?
More Questions on This Topic :
Question 10.
What is the output of this program?
class right....
Submit Solution