I have included some shift operator questions from JQ Plus which
I have troubles with. I know this should be a "breeze through" for the Gurus on this issue, but these questions have given me some headaches. Can anybody please make some comments on how the answers were derived
Question ID :952739435490
What would be printed during execution of the following program?
public class TestClass
{
public static void main(
String args[ ] )
{
shiftTest(1, "A" ) ;
shiftTest(1<<31, "B") ;<br /> shiftTest(1<<30, "C") ;<br /> shiftTest(-1, "D" ) ;<br /> }<br /> public static void shiftTest(int i , String str) <br /> {<br /> if (( i >> 1) != (i >>> 1)) System.out.println(str) ;
}
}
***************************************************************
b, d Can you please explain the concept
***************************************************************
Question ID :955935425650
Consider :
class A {}
class B extends A {}
class C extends B {}
Which of these boolean expressions correctly identifies when an object 'o' acutally refers to an object of class B and not A or C?
***************************************************************
(o instanceof b) && (!(o instanceof a))
(o instanceof B) && (!(o instanceof c)) //correct
!(!(o instanceof B) | | (o instanceof c)) // correct
(o instanceof B)&&!((o instanceof A)| |(o instanceof c))
***************************************************************
Question ID :954698538220
Which statments about the output of the following programs are true?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 0 ;
boolean bool1 = true;
boolean bool2 = false;
boolean bool = false;
bool = (bool2 & method1("1")); //1
bool = (bool2 && method1("2")); //2
bool = (bool1 | method1("3")); //3
bool = (bool1 | | method1("4")); //4
}
public static boolean method1(String str)
{
System.out.println(str);
return true;
}
}
*************************************************
1 and 3 will be part of the output?
Question:
*************************************************
Question ID :952739436700
What will be the outpout of the following program?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 0 ;
boolean bool1 = true ;
boolean bool2 = false;
boolean bool = false;
bool = ( bool2 & method1(i++) ); //1
bool = ( bool2 && method1(i++) ); //2
bool = ( bool1 | method1(i++) ); //3
bool = ( bool1 | | method1(i++) ); //4
System.out.println(i);
}
public static boolean method1(int i)
{
return i>0 ? true : false;
}
}
*************************************************
it will print 2
*************************************************
Question ID :961883785420
What would be printed during execution of the following program?
public class TestClass
{
public static void main(String args[])
{
System.out.print(" "+(1<<33)+" "+(1<<32)+" "+ Integer.toHexString(1<<31) );
}
}
*************************************************
what will this output?
*************************************************