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);
}
}
A. 25
B. 24
C. 32
D. 33
Answer: Option C
Solution(By Examveda Team)
The given Java code initializes a variableg
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
Comments ( 1 )
Related Questions on Data Types and Variables
What is the maximum value that can be stored in a byte variable in Java?
A. 127
B. 255
C. 32767
D. 64
What is the default value of an int variable in Java if it's not explicitly initialized?
A. 0
B. 1
C. -1
D. Null
Which of the following is not a valid identifier for a Java variable?
A. my_var
B. _myVar
C. 3rdVar
D. $var
How frist it add 1 point to g then multiply by 8