About Question enthuware.ocpjp.v8.2.1895 :
Moderator: admin
-
- Posts: 3
- Joined: Wed Nov 12, 2014 3:03 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1895 :
"All final or effectively final static variables"
You probably mean : "All final or effectively final variables"
You probably mean : "All final or effectively final variables"
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
No, because the question explicitly states, "...if the inner class is defined in a static method of encapsulating class.
-
- Posts: 15
- Joined: Tue Feb 25, 2014 3:14 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
One of the correct options is "All final or effectively final static or automatic variables".
Does this mean:
(1) All final or effectively final static variables and (2) all final or effectively final automatic variables?
Or, does it mean:
(1) All final or effectively final static variables and (2) all automatic variables?
Does this mean:
(1) All final or effectively final static variables and (2) all final or effectively final automatic variables?
Or, does it mean:
(1) All final or effectively final static variables and (2) all automatic variables?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
(1) All final or effectively final static variables and (2) all final or effectively final automatic variables.
-
- Posts: 1
- Joined: Thu Mar 25, 2021 2:05 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
"All final or effectively final static or automatic variables"
Only the effective final automatic variables defined in the defining static method. And of course the static ones.
Only the effective final automatic variables defined in the defining static method. And of course the static ones.
-
- Posts: 9
- Joined: Wed Jun 30, 2021 6:53 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
Exactly, automatic variables defined in other methods cannot be accessed, right?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
The the problem statement says "..the method..", which means it is talking about the method in which the inner class is defined. It is not about automatic variables of other methods. Automatic variables of one method are never accessible to other other methods anyway.
The explanation also includes a detailed example that illustrates the situation.
The explanation also includes a detailed example that illustrates the situation.
-
- Posts: 1
- Joined: Tue Sep 24, 2024 2:42 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
All instance variables is also partially correct. I can always access instance variable using object reference
Code: Select all
public class Test10 {
int ii = 20;
public static void inner() {
Test10 test10 = new Test10();
test10.ii++; //non final
class Inner {
public Inner() {
System.out.println(test10.ii);
}
}
new Inner();
}
public static void main(String[] args) {
Test10.inner();
}
}
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
Yes, "but using an object reference" is not specified in the problem statement and it would amount to using the field of another object and should not be assumed.
-
- Posts: 18
- Joined: Wed Feb 12, 2025 4:56 pm
Re: About Question enthuware.ocpjp.v8.2.1895 :
The two correct answers are conflicting. One says "All static variables" and one says "All effectively final static...". To me, the first correct answer is stating that all static variables, including ones that are NOT effectively final; which isn't correct, to my knowledge. Additionally, that contradicts the second correct answer. Am I missing something here?
-
- Site Admin
- Posts: 10384
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1895 :
>the first correct answer is stating that all static variables, including ones that are NOT effectively final;
Right, that is what it means. why do you think it is not correct?
The second option is not contradictory to the first in the context of the question. Second option doesn't say "Only". The variable covered by this statement are indeed accessible as required by the problem statement.
Right, that is what it means. why do you think it is not correct?
The second option is not contradictory to the first in the context of the question. Second option doesn't say "Only". The variable covered by this statement are indeed accessible as required by the problem statement.
-
- Posts: 18
- Joined: Wed Feb 12, 2025 4:56 pm
Re: About Question enthuware.ocpjp.v8.2.1895 :
My apologies. I was under the impression that the inner class could not access any members that weren't effectively final. I should have done more research before creating my previous post. That was the source of my confusion on both matters I mentioned in my post.
Who is online
Users browsing this forum: No registered users and 14 guests