Sometimes we would like a class that has just a single unique instance. Create a class Merlin that has one attribute, theWizard, which is static and of type Merlin. The class has only one constructor and two methods, as follows:

• Merlin—a private constructor. Only this class can invoke this constructor; no other class or program can create an instance of Merlin.
• summon—a static method that returns theWizard if it is not null; if theWizard is null, this method creates an instance of Merlin using the private constructor and assigns it to theWizard before returning it.
• consult—a nonstatic method that returns the string "Pull the sword
from the stone".


See the code in Merlin.java.

Computer Science & Information Technology

You might also like to view...

We do not use a long chain of ->next’s when working with a linked list (for example, ptr->next->next->next->next->next->info) because:

A. we often do not know how long the linked list is, so we use a loop to move a pointer through the list B. we can only use one next at a time (C++ does not permit more than one in an expression) C. it can become an infinite loop D. doing so can cause memory leak

Computer Science & Information Technology

What is the default PHP class access modifier?

a. protected b. private c. public d. variable

Computer Science & Information Technology

Primary tables represent the static lists of things that exist in a business such as customers, products, and suppliers. Related tables represent concepts or events

Indicate whether the statement is true or false

Computer Science & Information Technology

________ is code that could be used in several different Web pages if needed

Fill in the blank(s) with correct word

Computer Science & Information Technology