Q. Determine output:

Code:
public class Test{
      static int i = 5;
      public static void main(String... args){
            System.out.println(i++);
            System.out.println(i);
            System.out.println(++i);
            System.out.println(++i+i++);
      }
}
  • (A) 6 6 6 16
  • (B) 6 7 6 16
  • (C) 5 6 7 16
  • (D) 5 6 7 16D.5 6 6 16
πŸ’¬ Discuss
βœ… Correct Answer: (C) 5 6 7 16
Explanation: i++ : print value then increment (postfix - increment happens after the value of the variable is used) ++i : increment the print (prefix - increment happens before the value of the variable is used).
Explanation by: Shiva Ram
i++ : print value then increment (postfix - increment happens after the value of the variable is used) ++i : increment the print (prefix - increment happens before the value of the variable is used).

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
172
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Shiva Ram
Publisher
πŸ“ˆ
80%
Success Rate