Operators
Operators
Operators
6 (CX-310-065 , CX-310-066)
Subject: Operators
Total Questions : 16
Prepared by : http://www.techfaq360.com
1.22
2.50
3.10
4.Compilation fails with an error at line 4
Explanation :
B is the correct answer.
Question - 2
What is the output for the below code ?
Explanation :
B is the correct answer.
'a' == 'a' returns true. '5' == '5' returns true. 7 != 8 returns true because 7 is not equal to
8. 7.0 == 7L returns true.
Question - 3
What is the output for the below code ?
1.true true
2.true false
3.Compilation fails with an error at line 4
4.Compilation fails with an error at line 5
Explanation :
B is the correct answer.
From j2se 5.0 onwards you can compare Integer Object and int primitive type. So int5
== 5 return true. But int5 == '5' return false because '5' is char.
Question - 4
What is the output for the below code ?
1. import java.awt.Button;
2. public class Test {
3. public static void main(String... args) {
4. Button b = new Button("submit");
5. Button a = b;
6. Button c = a;
7. System.out.println(a == c);
8. }
9. }
1.true
2.false
3.Compilation fails with an error at line 5
4.Compilation fails with an error at line 6
Explanation :
A is the correct answer.
Both reference variables a and c refer to the same object. So a == c returns true.
Question - 5
What is the output for the below code ?
1.true false
2.false true
3.false false
4.Compilation fails with an error at line 6
Explanation :
B is the correct answer.
Question - 6
What is the output for the below code ?
Explanation :
B is the correct answer.
m1 and m2 refer to the same enum constant So m1 == m2 returns true BUT m1 and
m3 refer to different enum constant So m1 == m3 returns false. m1.equals(m2)
returns true because enum constant value is same (JAN and JAN). m1.equals(m3)
return false because enum constants values are different (JAN and FEB).
Question - 7
What is the output for the below code ?
public class A {
public void printValue(){
System.out.println("A");
}
}
1.true true
2.true false
3.false false
4.Compilation fails with an error at line 5 and 6
Explanation :
B is the correct answer.
instanceof operator is used for object reference variables to check whether an object is
of a particular type. reference variable b is a type of A BUT b is not type C.
Question - 8
What is the output for the below code ?
public class A {
public void printValue(){
System.out.println("A");
}
}
1.A
2.B
3.Compilation fails with an error at line 4
4.Compilation fails with an error at line 8
Explanation :
B is the correct answer.
instanceof operator is used for object reference variables to check whether an object is
of a particular type. In newValue(b); b is instance of B So works properly.
Question - 9
What is the output for the below code ?
public class A {
public void printValue(){
System.out.println("A");
}
}
1.true false
2.true true
3.false false
4.false true
Explanation :
B is the correct answer.
instanceof operator is used for object reference variables to check whether an object is
of a particular type. b and c reference variable are type of class A because B extends
A and then C extends B.
Question - 10
What is the output for the below code ?
interface A {
}
1.true false
2.true true
3.false false
4.false true
Explanation :
B is the correct answer.
instanceof operator is used for object reference variables to check whether an object is
of a particular type. b and c reference variable are type of interface A because B
implements A and then C extends B.
Question - 11
What is the output for the below code ?
1.true false
2.false false
3.true true
4.false true
Explanation :
B is the correct answer.
Question - 12
What is the output for the below code ?
1.true false
2.false false
3.true true
4.Compilation fails with an error at line 5
Explanation :
D is the correct answer.
Incompatible conditional operand types int[] and String. There is no way index could
ever refer to a String type.
Question - 13
What is the output for the below code ?
1.true
2.false
3.Compilation fails with an error at line 3
4.Compilation fails with an error at line 4
Explanation :
A is the correct answer.
Question - 14
What is the output for the below code ?
1.Value is 67 18 String 13
2.Value is 13 18 String 13
3.Value is 13 18 String
4.Compilation fails
Explanation :
A is the correct answer.
If the left hand operand is not a String then + operator treat as plus BUT if left hand
operand is a String then + perform String concatenation.
Question - 15
What is the output for the below code ?
1.5 6 7 16
2.6 6 6 16
3.6 6 7 16
4.5 6 6 16
Explanation :
A is the correct answer.
i++ : print value then increment (postfix - increment happens after the value of the
variable is used) ++i : increment the print (prefix - increment happens before the
value of the variable is used)
Question - 16
What is the output for the below code ?
1.feb
2.jan
3.march
4.Compilation fails with an error at line 4
Explanation :
A is the correct answer.
This is nested conditional with unbox. (i<21) is false goto (i<56), (i<56) is true so
result is "feb".