Java instance variable declare and Initialize in two statements

后端 未结 5 795
天命终不由人
天命终不由人 2020-12-04 03:38

Hi I\'m having problem with initialization in java, following code give me compile error called : expected instanceInt = 100; but already I have declared it. If these thing

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 04:22

    You can not have a separate statement to assign values to class members in the declaration area. You have to do this from a function, typically a class method.

    For your case, consider doing the assignment as soon as you declare.

提交回复
热议问题