Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating class objects: Newbie Question 1

Status
Not open for further replies.

Aleena

Programmer
Oct 3, 1999
27
US
Can you create a Class object within an if statement?<br>
I need to be able to create a specific type of object depending <br>
on input from the user. I am trying to use the following code <br>
but I get an invalid declaration error. Any suggestions for a different <br>
approach would be greatly appreciated. I am tearing my hair out.<br>
If you need to know any details just drop me an email at <br>
<A HREF="mailto:petersen@cdsnet.net">petersen@cdsnet.net</A>.<br>
<br>
if (type == 1)<br>
Account NewAcct = new Account(pw,owner,acc,sb);<br>
<br>
else if (type == 2)<br>
JrAccount NewAcctJr = new JrAccount(pw, owner, acc, sb, bday);<br>
<br>
<br>
Thanks for any help :)<br>
Aleena
 
Hi!<br>
<br>
You need to open a new &quot;code block&quot; with {.<br>
if (type==1) {<br>
Account NewAcct=new ...<br>
}<br>
else {<br>
JrAccount NewAccJr=new ...<br>
}<br>
<br>
Bye, Otto.<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top