Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

How to disable part of the super constructor in Java?

Thread view: 
John - 07 May 2007 20:53 GMT
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?
Greg R. Broderick - 07 May 2007 21:28 GMT
> 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!

Signature

---------------------------------------------------------------------
Greg R. Broderick                  usenet200705@blackholio.dyndns.org

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

Lew - 07 May 2007 22:06 GMT
"John" <rds1226@sh163.net> wrote:
>> 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.

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.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.