Page 1 of 1

About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sun Jul 05, 2020 1:05 pm
by robertath
Hello,
Here the 'a' variable is not static, so how can be used without create a new class reference? could you confirm please

Re: About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sun Jul 05, 2020 10:21 pm
by admin
The method m(), which contains a++, is also not static. It is an instance method. Every instance method has an implicit reference named "this", which points to the current instance of that class. So, a++; is actually this.a++;

Re: About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sat Apr 17, 2021 3:00 pm
by ACV001
"automatic variables" - another thing coming from C/C++. In java this term is never used.

Re: About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sat Apr 17, 2021 3:09 pm
by admin
ACV001 wrote:
Sat Apr 17, 2021 3:00 pm
"automatic variables" - another thing coming from C/C++. In java this term is never used.
Says who?
https://stackoverflow.com/questions/267 ... ic-in-java

Re: About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sun Apr 18, 2021 8:09 am
by ACV001
admin wrote:
Sat Apr 17, 2021 3:09 pm
ACV001 wrote:
Sat Apr 17, 2021 3:00 pm
"automatic variables" - another thing coming from C/C++. In java this term is never used.
Says who?
https://stackoverflow.com/questions/267 ... ic-in-java
Here's the definition from wikipedia:
In computer programming, an automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable's scope.
However, this term doesn't make sense in java world because in java, the programmer can't manually do allocation / deallocation like in C++, therefore all variables are by default considered automatic.

Also, there is no word "automatic" in JLS text.

Re: About Question enthuware.ocpjp.i.v11.2.937 :

Posted: Sun Apr 18, 2021 8:16 am
by admin
>therefore all variables are by default considered automatic.
The concept of stack and heap still apply in Java. Local variables (note, variables, not objects pointed to by the variables) are placed on the stack and go away when the method ends. Instance/static fields are different. They are not on the stack. They are part of the memory of the object and are deallocated as per GC rules.

>Also, there is no word "automatic" in JLS text.
That may be. The concept still exists and applies equally well.

If you have any references that say the term automatic is not applicable or is invalid in Java, please share.