Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

I do not understand what this means.

$
0
0
Ok I have been programming for five years now, however I have never learned the terms for variables or anything else. I just look at source code and are able to figure it out. I am currently in a class where one of the projects state this:

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 non-static method that returns the string "Pull the sword from the stone."

Ok with that said it would like me to test the class. This is what I have so far and the only thing it outputs is null.
package chapter6pp9;
public class Merlin{
    

public static Merlin theWizard;
private Merlin()       
{
    System.out.println("Pull the sword from the stone");
}
public static String summon(){   
    if (theWizard == null){
        Merlin staff = Merlin.theWizard;
            return staff.theWizard;}
    else {
        return consult();
    }
}
public String consult(){
    return "Pull the sword from the stone";
}
}


I am not looking for an answer to the problem, I am asking if I am doing this right and whether or not I have everything it asks, also the errors I get are in the return statements. It says it has found Merlin not String. Thank you for any help.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>