Java quiz 1 Answer
- B
-
B,D,E D-At line 3, we created a string object and its value is 'Java'. Because no new assignment was made, the new String object created with the 'concat()' method and the 'replace()' method was abandoned instantly. In the end, the value of 's' remains 'Java' False- 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.