ExamVeda
Login
Home
Data Types and Variables
?

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);
    } 
}

Answer & Solution
Correct Answer: Option C
The given Java code initializes a variable 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.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Hachalu Haile
Hachalu Haile 3 years ago
How frist it add 1 point to g then multiply by 8