What will be the output of the following code snippet?
int a = 10;
int b = 5;
System.out.println(a % b);
The % operator calculates the remainder of the division. In this case, 10 divided by 5 is 2 with a remainder of 0, so the output is 0.
Which of the following is true about the "switch" statement in Java?
Starting from Java SE 7, switch statements can use String values as case labels. break statements are not mandatory but are commonly used to prevent fall-through to subsequent cases.
What is the result of the following code?
int x = 5;
x += 3;
System.out.println(x);
The += operator adds the right operand (3) to the left operand (5) and assigns the result to the left operand. Thus, x becomes 8.
How does Java handle integer division when both operands are integers?
When both operands in an integer division are integers, Java performs integer division and truncates the result towards zero. For example, 5 / 2 results in 2, not 2.5.
Which of the following statements about Java methods is true?
Method overloading in Java allows multiple methods to have the same name but different parameter lists. This means you can overload methods by changing the type, number, or order of parameters. Methods can also have zero parameters and are not required to have multiple return statements.