?
What will be the output of the following Java code?
What will be the output of the following Java code?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
Answer & Solution
Correct Answer:
Option
C
The given Java code initializes a variable
The expression
Therefore, the output of the code will be
g with the value 3. It then uses the pre-increment operator (++) on g before multiplying it by 8 and printing the result using System.out.print.The expression
++g * 8 is evaluated as follows:++g increments the value of g to 4.4 * 8 is equal to 32.Therefore, the output of the code will be
32.
Join the Discussion
Login to post a comment or share your explanation.
Login