Operators Questions MCQs


operators Questions

Total Questions : 12

Question 1. Int x = 0, y = 0 , z = 0 ;
x = (++x + y-- ) * z++;
What will be the value of "x" after execution ?
  1.    -2
  2.    -1
  3.    0
  4.    1
  5.    2
Answer: Option C
Question 2. Int ++a = 100 ;
System.out.println( ++a ) ;
What will be the output of the above fraction of code ?
  1.    100
  2.    Displays error as ++a is not enclosed in double quotes in println statement
  3.    Compiler displays error as ++a is not a valid identifier
  4.    None of these
Answer: Option C
Question 3. What is the output of the following program ?
class Numbers{
public static void main(String args[]){
int a=20, b=10;
if((a < b) && (b++ < 25)){
System.out.println("This is any language logic");
}
System.out.println(b);
}
}
  1.    12
  2.    11
  3.    10
  4.    Compilation Error
Answer: Option C
Question 4. Select from among the following character escape code which is not available in Java.
  1.    \t
  2.    \r
  3.    \a
  4.    \\
  5.    \v
Answer: Option C
Question 5. What will be the output?
if(1 + 1 + 1 + 1 + 1 == 5){
System.out.print("TRUE");
}
else{
System.out.print("FLASE");
}
  1.    TRUE
  2.    FALSE
  3.    Compiler Error
  4.    None of these
Answer: Option A
Question 6. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
  1.    1 < x < 100 || x < 0
  2.    ((x < 100) && (x > 1)) || (x < 0)
  3.    ((x < 100) && (x > 1)) && (x < 0)
  4.    (1 > x > 100) || (x < 0)
Answer: Option B
Question 7. Public class Test{
      public static void main(String args[]){
            System.out.print(""=="");
            System.out.print(" ");
            System.out.print("A"=="A");
            System.out.print(" ");
            System.out.print("a==A");
      }
}
  1.    "==" A"=="A a==A
  2.    true true false
  3.    true true a==A
  4.    Compilation Fails
  5.    None of the above
Answer: Option C
Question 8. What will be the output?
public class Test{
public static void main(String args[]){
int a = 42;
double b = 42.25;
System.out.print((a%10)+" "+(b%10));
}
}
  1.    42 42.5
  2.    2 2.5
  3.    4.2 4.225
  4.    2 4.225
  5.    Compilation Error
Answer: Option B
Question 9. What will be the output after compiling and running following code?
1. public class Test{
2. public static void main(String... args){
3. int x =5;
4. x *= 3 + 7;
5. System.out.println(x);
6. }
7. }
  1.    22
  2.    50
  3.    10
  4.    Compilation fails with an error at line 4
  5.    None of these
Answer: Option B
Question 10. Determine output:
public class Test{
public static void main(String... args){
int a=5 , b=6, c=7;
System.out.println("Value is "+ b + c);
System.out.println(a + b + c);
System.out.println("String " + (b+c));
}
}
  1.    Value is 67 18 String 13
  2.    Value is 13 18 String 13
  3.    Value is 13 18 String
  4.    Compilation fails
  5.    None of these
Answer: Option A
Question 11. What will be the output for the below code ?
class A{
public void printValue(){
System.out.println("A");
}
}
class B extends A{
public void printValue(){
System.out.println("B");
}
}
1. public class Test{
2. public static void main(String... args){
3. A b = new B();
4. newValue(b);
5. }
6. public static void newValue(A a){
7. if(a instanceof B){
8. ((B)a).printValue();
9. }
10. }
11. }
  1.    A
  2.    B
  3.    Compilation fails with an error at line 4
  4.    Compilation fails with an error at line 8
  5.    None of these
Answer: Option B
Question 12. Determine output:
public class Test{
static int i = 5;
public static void main(String... args){
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
System.out.println(++i+i++);
}
}
  1.    6 6 6 16
  2.    6 7 6 16
  3.    5 6 7 16
  4.    5 6 6 16
  5.    None of these
Answer: Option C