[HD Pg 0, Sec. 1.5.1 - static-and-instance]

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

Moderator: admin

Post Reply
arganesh3
Posts: 3
Joined: Mon Dec 16, 2019 6:06 pm
Contact:

[HD Pg 0, Sec. 1.5.1 - static-and-instance]

Post by arganesh3 »

How a static method can be accessed with a variable of the class?

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

Re: [HD Pg 0, Sec. 1.5.1 - static-and-instance]

Post by admin »

Did you read point 2 under "Important points about static"? It shows exactly how:
Even though static fields belong to a class and should be accessed through the name of the class, for example, Account.numberOfAccounts, it is not an error if you access it through a variable of that class, i.e., acct1.numberOfAccounts.

arganesh3
Posts: 3
Joined: Mon Dec 16, 2019 6:06 pm
Contact:

Re: [HD Pg 0, Sec. 1.5.1 - static-and-instance]

Post by arganesh3 »

Yes, I read that but not able register in mind. As I always refer it (acct1. or acct2.) as Object or Instance of Class. Not used to be calling it as a variable. Somehow when I read variable i think (int i) only. Is reference variable the right term? Correct me if my assumption is wrong.

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

Re: [HD Pg 0, Sec. 1.5.1 - static-and-instance]

Post by admin »

"Reference variable" is the right term. A reference variable points to an object. A primitive variable does not point to any object. But both are variables. Please go through Section 1.4 "Object and Reference" again, carefully. It is explained in detail there.

arganesh3
Posts: 3
Joined: Mon Dec 16, 2019 6:06 pm
Contact:

Re: [HD Pg 0, Sec. 1.5.1 - static-and-instance]

Post by arganesh3 »

Thanks for the clarification!

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests