Forums Register Login

How to enter 2 parameters of the same type in a class constructor

+Pie Number of slices to send: Send
I get an error from from java compiler when I am trying to enter a class constructor with 4 parameters 2 of which are of the same type.Any ideas how to solve this?

code :

public Invoice ( String pNumber, String pDescription, int iQuantity, double iPrice )
+Pie Number of slices to send: Send
That code looks fine and it certainly is legal to have multiple parameters of same type. Sounds as if you may have misinterpreted the compiler's complaints. Can you post the compiler output?
+Pie Number of slices to send: Send
I use eclipse with sdk6 compiler.The error i get is that :

Duplicate method Invoice(String) in type Invoice
+Pie Number of slices to send: Send
That's telling you that you have two constructors, both of which take the same parameter list, a String. So somewhere, you have

followed by

The parameter list must be different somehow. You're best bet is to take one out.
[ February 07, 2007: Message edited by: Fred Rosenberger ]
+Pie Number of slices to send: Send
There is no other constructor in this class.Thnx for the immediate replies!
+Pie Number of slices to send: Send
Here's the complete code list so far :

public class Invoice
{
private String partNumber, partDescription; //part number and part description
private int itemQuantity; //item quantity
private double itemPrice; //item price

//constructors initialize all four instance variables
public Invoice ( String pNumber, String pDescription, int iQuantity, double iPrice )
{
partNumber = pNumber; //initializes partNumber;
partDescription = pDescription; //initializes partDescription
itemQuantity = iQuantity; //initializes itemQuantity
itemPrice = iPrice; //initializes itemPrice
} //end constructor1
+Pie Number of slices to send: Send
It compiles fine, with *no* errors when I tried it.
+Pie Number of slices to send: Send
Are you sure you're actually compiling the file you think you're compiling? Sometimes, one can get confused about directories. To be sure, rename or move the file you think you're compiling then try the compilation again. If it still compiles, you'd better find that other file!
+Pie Number of slices to send: Send
Which line does the error point to? (Just double-click on the error in the problems view.)
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1166 times.
Similar Threads
Valid places to call a constructor from
Overload constructor
passing arguments from command line
A question on constructor
default constructors and constructors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:41:35.