How to disable part of the super constructor in Java?

J

John

I am writing a test system in Java.

According to my current design, True/False question is a sub class of
multiple choice question.

I have a problem here:

Multiple choice's constructor looks like this:

public multipleChoiceQuestion(boolean isQuiz)
{
choice=new choices();
setChoicesDone=false;
answer=new answers();
System.out.print("You have choosen to enter an multiple choice
question.Please enter the question below.\nPlease type here:>");
}

True False's like this:

public trueFalseQuestion(boolean isQuiz)
{
super(isQuiz);
choice=new choices("True", "False");
System.out.print("You have choosen to enter an true false question.Please
enter the question below.\nPlease type here:>");
}

The problem is that when the true false question is initalized the two print
out all show on the screen like this:

You have choosen to enter an multiple choice question.Please enter the
question below.
Please type here:>You have choosen to enter an true false question.Please
enter the question below.
Please type here:>

How can I disable the first one for multiple choice? Perhap I can let the
super() redirected to NULL?
 
G

Greg R. Broderick

John said:
How can I disable the first one for multiple choice? Perhap I can let the
super() redirected to NULL?

Extract the System.out.println() to another method in both classes, one that
does not call super.

Call this new method in your code that is presently calling the c'tor.

Cheers!

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 
L

Lew

Extract the System.out.println() to another method in both classes, one that
does not call super.

Call this new method in your code that is presently calling the c'tor.

As a general rule, don't do anything in a constructor that is not
construction. Do actions in methods, not in constructors.
choice=new choices();
answer=new answers();

Also, by convention your class names should begin with an upper-case letter.
setChoicesDone=false;

Using "set" as the prefix to a variable name is also somewhat jarring to those
accustomed to that as the start of a method name. Readability is enhanced if
you use nomenclature from a widely-used convention like the Bean accessor
patterns only for that convention.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,105
Latest member
sheetaldubay7750ync
Top