Examveda
Examveda

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

A. 25

B. 24

C. 32

D. 33

Answer: Option C

Solution(By Examveda Team)

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.

This Question Belongs to Java Program >> Data Types And Variables

Join The Discussion

Comments ( 1 )

  1. Hachalu Haile
    Hachalu Haile :
    4 months ago

    How frist it add 1 point to g then multiply by 8

Related Questions on Data Types and Variables