About Question enthuware.ocajp.i.v7.2.955 :

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

Moderator: admin

Post Reply
Travis Grey
Posts: 4
Joined: Sun Mar 24, 2013 9:22 am
Contact:

About Question enthuware.ocajp.i.v7.2.955 :

Post by Travis Grey »

Hi!

The question "An instance member ..." has 2 correct options:

1) can be a variable, a constant or a method.
2) belongs to an instance of the class.


But "constant" by definition should be "static" (and "final"), that is "constants are not instance member".
Please, help to understand.

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

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by admin »

Travis Grey wrote: But "constant" by definition should be "static" (and "final")
That is not true. A constant is something that doesn't change. So final, yes. But static or instance is a completely unrelated thing.

Metz123
Posts: 1
Joined: Wed Dec 18, 2013 8:28 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by Metz123 »

"An instance member is a member variable or a member method that belongs to a specific object instance."
Does a member method really belong to an instance? If you have a (non-static) member function foo() and 2 instances i1 and i2, the member function foo() is absolutely equal for both instances, isn’t it? Or is it defined as different due to the hidden parameter “this”.

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

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by admin »

That is right. Instance method operates on the particular instance of that class ("this").

-Paul.

Denn777
Posts: 4
Joined: Sat Mar 14, 2015 5:19 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by Denn777 »

Travis Grey is right.
Constants are not instance members.
"Constants" chapter:
http://docs.oracle.com/javase/tutorial/ ... svars.html

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

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by admin »

As per JLS Section 4.12.4:
A variable of primitive type or type String, that is final and initialized with a compile-time constant expression, is called a constant variable.
This implies that being static is not a requirement for a variable to be constant.

HTH,
Paul.

dvc1190
Posts: 15
Joined: Tue Feb 25, 2014 3:14 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by dvc1190 »

This question doesn't distinguish between a run-time constant and a compile-time constant. Per Oracle documentation, a Java constant is a compile time constant, so it must be static and final. A compile-time constant is also what most people in the field will mean when they use the term "constant".

If the test really will be vague about "constant", then this question can remain. Otherwise, please change this question as your justification is misleading.

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

Re: About Question enthuware.ocajp.i.v7.2.955 :

Post by admin »

The answer and explanation are correct. Please go through the Java language specification quoted above.
A constant - irrespective of whether it is compile time or run time - doesn't have to be static.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests