logo

CuriousTab

In the following pieces of code, B and D will compile without any erro

Discussion


Home Certification Oracle Certification Comments
Share: 

  • Question
  • 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;


  • Options
  • A. TRUE
  • B. FALSE

  • Correct Answer
  • TRUE 

    Explanation

    The code segments B and D will compile without any error. A is not a valid way to construct a StringBuffer, you need to create a StringBuffer object using "new". B is a valid construction of a Boolean (any string other than "true" or "false" to the Boolean constructor will result in a Boolean with a value of "false"). C will fail to compile because the valid range for a byte is -128 to +127 (i.e., 8 bits, signed). D is correct, 0x1234 is the hexadecimal representation in java. E fails to compile because the compiler interprets 1.2 as a double being assigned to a float (down-casting), which is not valid. You either need an explicit cast, as in "(float)1.2" or "1.2f", to indicate a float.

  • Tags: Analyst, IT Trainer, Project Manager
    Similar Questions
  • 1. 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); } Solve it....

  • 2. Why do you need common fields in a Database? Solve it....

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

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

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

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

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

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

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

  • 10. How many joining conditions are required to join 4 tables in SQL? Solve it....


  • Comments

    There are no comments.

Enter a new Comment