Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:48:18+00:00 2026-06-03T16:48:18+00:00

The output of this code is: c: 1 , id: 0 I want to

  • 0

The output of this code is:

c: 1 , id: 0

I want to know why the output is not:

c: 0 , id: 1

class A {
    private static long c;
    private final long id = c++;
    public A() {
       print("c: " + c + " , id: " + id);
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:48:21+00:00Added an answer on June 3, 2026 at 4:48 pm

    Because an expression like c++ operates like this:

    • Evaluate c; remember this (e.g. tmp = c😉
    • Increment c
    • The result of the expression is the original value (tmp)

    So in this case, you start off with c = 0, so id becomes 0… but c is incremented in the process, so c is 1 after the expression has been evaluated.

    See section 15.14.2 of the Java Language Specification for more details. Extract:

    At run-time, if evaluation of the operand expression completes abruptly, then the postfix increment expression completes abruptly for the same reason and no incrementation occurs. Otherwise, the value 1 is added to the value of the variable and the sum is stored back into the variable. Before the addition, binary numeric promotion (§5.6.2) is performed on the value 1 and the value of the variable. If necessary, the sum is narrowed by a narrowing primitive conversion (§5.1.3) and/or subjected to boxing conversion (§5.1.7) to the type of the variable before it is stored. The value of the postfix increment expression is the value of the variable before the new value is stored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I expet that this code should output: 8 8 but it does not. class
In short: For this code: Encoding.ASCII.GetBytes(‚) I want the output to be 130, but
I want to output the score of documents. The code I write for this
This code produces a different output in Python 2 and Python 3 . class
Can you explain to me the output of this Java code? int a=5,i; i=++a
This code: wget --output-document=- http://runescape.com/title.ws 2>/dev/null \ | grep PlayerCount \ | head -1l
This code will output some blinks on divs when we do the mouse over.
This code when executed displays the expected output but prints segmentation fault (core dumped)
This code executes handbrakecli (a command line application) and places the output into a
When I run this code, the output is 11, 10. Why on earth would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.