Hello,
Here the 'a' variable is not static, so how can be used without create a new class reference? could you confirm please
About Question enthuware.ocpjp.i.v11.2.937 :
Moderator: admin
-
- Posts: 1
- Joined: Sat Jul 04, 2020 2:03 pm
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.937 :
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++;
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Sep 11, 2015 9:13 am
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.937 :
"automatic variables" - another thing coming from C/C++. In java this term is never used.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.937 :
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Fri Sep 11, 2015 9:13 am
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.937 :
Here's the definition from wikipedia:admin wrote: ↑Sat Apr 17, 2021 3:09 pmSays who?
https://stackoverflow.com/questions/267 ... ic-in-java
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.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.
Also, there is no word "automatic" in JLS text.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.i.v11.2.937 :
>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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 111 guests