logo

CuriousTab

What is the output after compile and run the following code ? int Outp

Discussion


Home Certification Oracle Certification Comments
Share: 

  • Question
  • What is the output after compile and run the following code ? int Output = 10; boolean b = false; if((b == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); }


  • Options
  • A. Compilation and output of "We are equal 10"
  • B. Compilation and output of "Not equal! 10"
  • C. Compilation error, attempting to perform binary comparison on logical data type
  • D. Compilation and output of "Not equal! 20"

  • Correct Answer
  • Compilation and output of "Not equal! 10" 

    Explanation

    The output will be "Not equal! 10". Please note that && is logical AND operator. If first operand before (&&) is false then the other operand will not be evaluated. This illustrates that the Output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. If you change the value of b1 to true, processing occurs as you would expect and the output would be "We are equal 20".

  • Tags: Analyst
    Similar Questions
  • 1. Why do you need common fields in a Database? Solve it....

  • 2. Difference between Candidate key and Primary key? Solve it....

  • 3. What is the maximum number of triggers, can apply to a single table? Solve it....

  • 4. Which dml command is used in conjunction with @@identity? Solve it....

  • 5. What is Primary Key in DBMS? Solve it....

  • 6. In the following pieces of code, B and D will compile without any error. True or false ? A: StringBuffer sb1 = "abcd"; B: Boolean b = new Boolean("abcd"); C: byte b = 255; D: int x = 0x1234; E: float fl = 1.2; Solve it....

  • 7. Define Executive Plan in Database SQL ? Solve it....

  • 8. Insert command falls in which sub-language of SQL ? Solve it....

  • 9. In R-DBMS, the data is organized in the form of _____. Solve it....

  • 10. What are the different types of SQL statements ? Solve it....


  • Comments

    There are no comments.

Enter a new Comment