J
Q. What is the output for the below code ?
1. public class Test{ 2. public static void main(String[] args){ 3. byte b = 6; 4. b+=8; 5. System.out.println(b); 6. b = b+7; 7. System.out.println(b); 8. } 9. }
int or smaller expressions always resulting in an int. So compiler complain about Type mismatch: cannot convert from int to byte for b = b+7; But b += 7; // No problem because +=, -=, *=, and /= will all put in an implicit cast. b += 7 is same as b = (byte)b+7 so compiler not complain.
You must be Logged in to update hint/solution
Be the first to start discuss.
Q. Decrement operator, −−, decreases the value of variable by what number?
Q. What will Collections.sort internally uses when number of elements are less than 7?
Q. Arithmetic operators in java can not be applied to
Q. Which of the following method call is valid to obtain the server's hostname by invokingan applet?
Q. Numbers with fractional are called __________.
Q. Which one loop is also known as Entry Control loop
Q. How many constructors does the class Exception have?
Q. Exception Handling is a mechanism to handle runtime errors
Discusssion
Login to discuss.