Home / Programming MCQs / JAVA MCQs / Question
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
Which packages represent interfaces and classes for servlet API?
Which class is used to load the JDBC driver?
What is the output of a Bitwise AND (&) operation if both the inputs/operands are 1s?
Which is correct about an instance variable of type String?
Variable declared as _________ do not occupy memory on a per instance basis.
What is the output of the following program?
Which one of the following is correct for directive in JSP?
What is the output of the below Java code snippet?
Which of the following is a method having same name as that of its class?
Discusssion
Login to discuss.