About Question enthuware.ocpjp.v8.2.1444 :
Moderator: admin
-
- Posts: 33
- Joined: Sat Feb 15, 2020 12:44 am
- Contact:
About Question enthuware.ocpjp.v8.2.1444 :
I was confused by the fact that the second option had an implemented method despite being abstract. But of course this is possible.
-
- Posts: 34
- Joined: Mon Oct 30, 2023 11:55 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
Could you give an example for
If I understand right, I need to send an Outer's reference as a parameter to a method of the static Inner class, or?You can access d from a static inner class by using a reference to an instance of Outer.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
You do not necessarily need to send a reference as an argument. You can also do this:
Code: Select all
class Outer
{
private double d = 10.0;
static class SI {
{
System.out.println(new Outer().d);
}
void m(){
System.out.println(new Outer().d);
}
}
}
If you like our products and services, please help us by posting your review here.
-
- Posts: 34
- Joined: Mon Oct 30, 2023 11:55 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
Thank you a lot. It looks strange. You create new instance of Outer class. SI and method m() have different instances of Outer(). You may create any instance. There is no any connection between Outer and SI only name space. Sorry its not fully clear. Could you please give a link to clarify.
Thank you a lot one more time.
Thank you a lot one more time.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
In the example I showed above, I am accessing Outer's d from a static inner class. Yes, they are not same instances. If you want same Outer instance, of course you have to share that instance's reference some how. I am not sure which part is not clear to you and which link are you asking for.
If you like our products and services, please help us by posting your review here.
-
- Posts: 34
- Joined: Mon Oct 30, 2023 11:55 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
Static class does not have access to "this" (if i do not use DI, for example) it means that it does not have access to instance. If you create new instance it means that you have access to class and may create an instance. Please correct me if I wrong. I think now its clear. Thank you.You can access d from a static inner class by using a reference to an instance of Outer.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1444 :
We are talking about static inner class, so obviously, it has access to its enclosing class.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 11 guests