Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

HOME

anilbachi SCJP Practice Exams

chapter1 | chapter2 | chapter3 | chapter4 | chapter5 | chapter6 |

chapter7 | chapter8 | chapter9 | chapter10 | chapter11 |

Chapter 2: Operators and Assignments Questions

Q1:The java operator which performs a right shift of an integer primitive value without extending the sign bit.

a).>>

b).>>>

c).<<

 

Q2:What is the output of the following statement.

X=20; System.out.println(x++);

a).20

b).19

c).21

d).0

 

Q3:Which of the following assignments causes a compile error with the following variables defined.

char c;

int i;

a). c='A';

b). i=10;

c). i=c;

d). c=i+1;

 

Q4: State the value of flags[0] when the following statement is compiled .

boolean flags[]=new boolean[100];

a).true

b).null

c).NULL

d).false

 

Q5:Given two int variables initialized as follows:

int a=63;

int b=4;

what is the value of a&b.

a).63

b).4

c).null

d).0

 

Q6:Given two int variables initialized as follows.

int a=63;

int b=4;

what is the value of a&&b?

a).63

b).4

c).null

d).runtime exception occurs can't convert int to boolean.

 

Q7: Given two int variables initialized as follows:

int a=63;

int b=4;

which of the following expression initializes c to 59.

a).int c=a | b;

b).int c=a ^ b;

c).int c=a & b;

d).int c=a >> b;

 

Q8:Given the following variable declarations

boolean b=false;

Boolean a=new Boolean();

state the consequence of the following statement:

if(a.equals(b)) System.out.println("Equal");

else System.out.println("Not equal");

a).output is Not equal

.b).output is equal

c).the code will not compile

d).none

Q9:Which of the following assignments are invalid

a). double d=2.3;

b). byte b=12;

c). int I='12';

d). float f=2.3;

e). short s=28;

 

Q10:State the possible output of the following statements

int a=12;

System.out.println(a/0);

a).0

b).null

c).infinity

d).a compile time exception occurs.

 

Q11:State the output of the following statements

double d=3.123;

int i=0;

System.out.println(d/i);

a).0

b).null

c).an Arithmetic Exception is generated

d).infinity

 

Q12:Which of the following operation are known as short circuit operators

a). &

b). |

c). &&

d). ||

e). a and b

f).c and d

g).none

 

Q13:State the output of the following code

public class short{

public static void main(String args()){

int t=0;

boolean t=true;

boolean f=false,b;

b=(t || ((i++) ==0));

b=(f || ((i+=2)>0));

System.out.println(i);

}}

a).0

b).1

c).2

d).3

 

 

Q14:What is default integer primitive

a).char

b).short

c).int

d).long

 

Q!5:Java is entitled with which of the following types of operators.

a).unary

b).binary

c).ternary

d).a,b

e).a,b,c

 

Q16:Which among the following is a valid conversion

a). integer to boolean primitive

b). Numeric to reference variable

c).Reference to Numeric

d).between two array types

e).byte to integer

 

Q17:Which among the following statements are true in case of a arithmetic expression evaluation

a).if either operand is a double,the other is converted to double

b).if either operand is a float the other is converted to float

c).if either operand is of type long then the other is conveted to long

d).if either operand is of type int the other is converted to int

e).if either operand is a short the other is converted to short

f).all the above

 

Q18:A byte variable is declared as

byte X=0; the expression X+=4; is equivalent to

a). X=X+4;

b). X=(byte)X+4;

c). X=(byte)(X+4);

d). none

 

Q19: Two short variables are declared as

short a=10;

short b=11;

the result of the following assignments is

short d=a & b ;

a).no error occurs and result is 10

b).a compiler error occurs "Explicit cast is required to convert int to short".

c).none

 

Q20:Given the following variables

int X=10;

int Y=12;

select the correct answer for the following statement

if (X>1 || Y<12)

a).both operands are evaluated

b).first operand only is evaluated

c).seconnd operand only is evaluated

d).no operand is evaluated

 

Q21:The following code creates a long object and an Integer object,both with the same value.

Long c=new Long(42);

Integer b=new Integer(42);

if(a.equals(b)) System.out.println("Equal");

else System.out println("Notequal");

what is the output when the two objects are compared with the equals method?

a). Equal

b). Notequal

 

Q22:The folowing codes creates two Integer objects having the same value:

Integer X=new Integer(97);

Integer Y=new Integer(97);

if(X==Y) System.out.println("Equal");

else System.out.println("Not Equal");

what is the result when the two objects are compared ?

a). Equal

b). Not Equal

 

Q23:Given the following code:

1. String X="one";

2. String Y="two";

3. X+=Y+"three";

what is contained in X?

a). one two

b). one two three

c). two three

d). null

 

Q24:What is the result of compiling the code

String a="file";

String b=".txt";

String c=a-b;

a). c contains "file"

b). c contains "file.txt"

c). results in compiletime error

d). c contains null

 

Q25:What is the result after the following code is executed

1. int X=2;

2. int Y=3;

3. int Z=(X=Y)*X+Y;

a). X contains 3, Y contains 7

b). X contains 2,Y contains7

c). X contains 3,Y contains 12

d). X contains 3,Y contains 18

 

Q26:Which of the following statements are invalid

a). address instanceof Object

b). address instanceof String

c). address instanceof 100

d). address instanceof Object[]

 

Q27:Which of the following statements are valid

a).address instanceof null

b).address instanceof NULL

c).address instanceof 100

d).address instanceof Object

 

Q28:Which of the following operators evaluates both the operands always.

a). &&

b). &

c). ||

d). none

 

Q29: Given a is an integer what can be said about c after the statement

int c=a<<2;

a). the result is always positive

b).the result is always negative

c).the result is may be positive or negative

 

Q30:Which operator is used to perform bitwise inversion in java

a). ~

b). !

c). &

d). |

e). ^

 

Q31:Given a byte variable

byte X=3

state the result of (byte)~X;

a).3

b).0

c).-4

d).-3

 

Q32:Which operator is an bitwise exclusive or

a). &

b). ^

c). |

d). ~

 

Q33:Given two integers by

X=5>>2;

Y=X>>>2;

state the value of Y

a).5

b).2

c).80

d).0

e).64

answer:d

Q34:State the output of the following code

public class test{

public static void main(String args()){

int X=0,Y=1,Z;

if(X) Z=0;

else Z=1;

if(Y) Z=2;

else Z=3

System.out.println(Z);

a).0

b).1

c).2

d).3

e).results in a compile time error

 

 

Click here for solutions

 

Copyrights bachi2000.8m.com All rights reserved

for queries contact anil_kuchana@yahoo.com