|
-
February 24th, 2000, 07:18 AM
#1
Another constructor question
Does anyone understand how to take an object of my Distance class as an argument?
"The fourth and final constructor must take an object of the Distance class as an argument. This constructor will copy the instance variable values from the argument object to the object being instantiated. "
The following is what I have but I keep getting error
// default constructor
public int Distance()
{
feet = yards = miles = 0;
}
//second constructor //
public Distance(int f) { feet = f; }
//third constructor//
public Distance(int y, char units) // Both variables cannot be named y, so I named the second units.
{
switch(units)
{
case 'f':
case 'F':
feet = y;
break;
case 'm':
case 'M':
miles = y;
break;
case 'y':
case 'Y':
yards = y;
break;
default:
feet = yards = miles = 0; }
//fourth argument
public int Distance(int arg1)
{
feet = arg1;
}
}
This will not compile.
not sure what is wrong
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|