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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
robertath
Posts: 1
Joined: Sat Jul 04, 2020 2:03 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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++;
If you like our products and services, please help us by posting your review here.

ACV001
Posts: 9
Joined: Fri Sep 11, 2015 9:13 am
Contact:

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

Post by ACV001 »

"automatic variables" - another thing coming from C/C++. In java this term is never used.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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
If you like our products and services, please help us by posting your review here.

ACV001
Posts: 9
Joined: Fri Sep 11, 2015 9:13 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 90 guests