About Question enthuware.ocajp.i.v8.2.1360 :

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

Moderator: admin

Post Reply
Javier
Posts: 66
Joined: Mon Feb 20, 2017 12:31 pm
Contact:

About Question enthuware.ocajp.i.v8.2.1360 :

Post by Javier »

Hi!
I understood that it is not possible to use this from a static context,
so why
i= this.i2; is legal? (i2 is static)

Thank you very much!!

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

Re: About Question enthuware.ocajp.i.v8.2.1360 :

Post by admin »

You have misunderstood the meaning the term "static context".
If you observe method1 closely, you will notice that it is an instance method. So the context in which this.i2 is present is not static. Therefore, "this" is available in this method and that is why this.i2 is valid.

Also remember that i2 is static and it is valid to access static members from static as well as non-static contexts.

Javier
Posts: 66
Joined: Mon Feb 20, 2017 12:31 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1360 :

Post by Javier »

Thank you very much for the explanation Enthuware!
I got it now!

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests