Professional Documents
Culture Documents
Operators 2 My Part 12-18
Operators 2 My Part 12-18
Operators 2 My Part 12-18
Answer : B,C,D,E
A.Cosidering the first statement; it should be correct. If we write a code like this,
B. The “Instance Of” operator is used in determining, if a given object is of the type of a specific class.It is
a binary operator, first operand sholud be an object and second operand should be a class name. The
manipulation should be like follows,
(object instanceOf class name)
Here it says that a reference to a primitive array can also be checked by, using instanceof operator.
Primitive array consisting primitive data type variables, can’t have a connection with objects. So I
assume that this statement might be wrong.
C. This statement is wrong because relational operators compare two operands and always return either
true or false.
D.Logical operators and Bitwise Operatos are really tricy, because they look like almost same, if you give
two boolean operands it’ll behave like a logical operator and return a boolean value and, if the operands
are numerical, operator ‘ll act like in bitwise manner and result a numerical answer. But here in this
scenario, clearly question says that logical operator is used, so the answer should be a boolean. And
there’s no way to result non boolean value and that relization make it confirmed; that statement D is
wrong.
class A{
public static void main (String args []){
System.out.println(5+2 == “” + 5 + 2 );
}
}
What is the result?
A . true
B.false
C.No output
D.Compilation Error
E. Runtime Exception
Answer : D
Before explaining the answer, I would like to show you some examples, which will help to understand
the situation. The following code compiles fine, gives shown out put,
Compiler consider one side of the == as a String and the other side as an integer, thus can’t be campare
15. Consider the following code
class A {
public static void main (String args[]){
boolean a = false;
boolean b = !a;
boolean c = (a^ !b);
System.out.println(a| b ^ c & ! a );
System.out.println(((a | b ) ^ c ) & ! a );
}
}
What is the result?
A. True true
B. False false
C. True false
D. False true
E. Compilation Error
F. Runtime Exception
Answer : A
When looking at the code, wwe can recognize various logical operators which have been used. Not, OR ,
Ex-OR and AND operators are among them. If you carefully examine the code, you can understand that
the result is true in both situations.
Output :
Class A {
public static void main (String args[]){
int x=10;
float y=30.0F;
long z=x*y;
double d = (x<y) ? z : (y<x) ? y : x;
System.out.println(d);
}
}
What is the result ?
A. 10.0
B. 30.0
C. 300.0
D. 300
E. Compilation Error
F. Runtime Exception
Answer : E
If you try to compile the preceding code, you’ll met up with a compile error.
1. 7,1,1.8
2. 2,-1,1.0
3. 2,1,1.8
4. None of the above
Answer : 4
We can write a simple java program to justify the answer.
s 2
a -1
x 1.8
First two calculations are simple and you just need to know the basic behaviour of modulus operator.
And the final one is regarding numbers with decimal points and the answer I assumed can be proved
through java coding in the above way.
18. class V{
Public static void main(String args[]){
System.out.print((0.0%-1)+”,”+(-0.0%1)+”,”+(-0.0%-1));
}
}
Answer : b
Although the answers of the question cotain very similar answers, and looks scary, the question isn’t so
difficult.
Good knowledge about different situations where the % operator can be used with (-) numbers, is
important, to get exactly the correct answer.