About Question enthuware.ocajp.i.v7.2.955 :
Moderator: admin
-
- Posts: 4
- Joined: Sun Mar 24, 2013 9:22 am
- Contact:
About Question enthuware.ocajp.i.v7.2.955 :
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.
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.
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
That is not true. A constant is something that doesn't change. So final, yes. But static or instance is a completely unrelated thing.Travis Grey wrote: But "constant" by definition should be "static" (and "final")
-
- Posts: 1
- Joined: Wed Dec 18, 2013 8:28 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
"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”.
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”.
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
That is right. Instance method operates on the particular instance of that class ("this").
-Paul.
-Paul.
-
- Posts: 4
- Joined: Sat Mar 14, 2015 5:19 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
Travis Grey is right.
Constants are not instance members.
"Constants" chapter:
http://docs.oracle.com/javase/tutorial/ ... svars.html
Constants are not instance members.
"Constants" chapter:
http://docs.oracle.com/javase/tutorial/ ... svars.html
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
As per JLS Section 4.12.4:
HTH,
Paul.
This implies that being static is not a requirement for a variable to be constant.A variable of primitive type or type String, that is final and initialized with a compile-time constant expression, is called a constant variable.
HTH,
Paul.
-
- Posts: 15
- Joined: Tue Feb 25, 2014 3:14 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
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.
If the test really will be vague about "constant", then this question can remain. Otherwise, please change this question as your justification is misleading.
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.955 :
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.
A constant - irrespective of whether it is compile time or run time - doesn't have to be static.
Who is online
Users browsing this forum: No registered users and 15 guests