The number 2 "Add a private static...", this is not present on the code. So, the answer "Add a static method that returns an instance of SpeedSensor." will not be correct because, every time you will call this method, a new instance will be created and delivered to the client.1. Make the constructor of the class private so that no one can instantiate it except this class itself.
2. Add a private static variable of the same class to the class and instantiate it.
3. Add a public static method (usually named getInstance()), that returns the class member created in step 2.
About Question enthuware.ocpjp.v7.2.1105 :
Moderators: Site Manager, fjwalraven
-
- Posts: 28
- Joined: Wed Feb 25, 2015 9:03 am
- Contact:
About Question enthuware.ocpjp.v7.2.1105 :
Here in this question, as well explained:
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1105 :
The variable in 2 is not there that is why it is asking you to add the variable. So I am not sure I understand you question?
Why do you think every time you will call this method, a new instance will be created and delivered to the client?
Why do you think every time you will call this method, a new instance will be created and delivered to the client?
-
- Posts: 28
- Joined: Wed Feb 25, 2015 9:03 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1105 :
Sir, can you please show me where "it is asking you to add the variable"?
I think every time I call this method, a new Instance will be returned, since there is no instance variable to store this instance, and this method only will be possible returning a new Instance(); every time.
I think every time I call this method, a new Instance will be returned, since there is no instance variable to store this instance, and this method only will be possible returning a new Instance(); every time.
-
- Site Admin
- Posts: 10389
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1105 :
Ok, I see the confusion. The options do not contain all the changes that are required. You are right that as such the problem statement implies that if you select correct options, Singleton pattern will be implemented.
I have updated the question statement to reflect that.
thank you for your feedback!
Paul.
I have updated the question statement to reflect that.
thank you for your feedback!
Paul.
Who is online
Users browsing this forum: No registered users and 2 guests