aspose file tools*
The moose likes Beginning Java and the fly likes How to enter 2 parameters of the same type in a class constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to enter 2 parameters of the same type in a class constructor" Watch "How to enter 2 parameters of the same type in a class constructor" New topic
Author

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

Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
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 )
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
I use eclipse with sdk6 compiler.The error i get is that :

Duplicate method Invoice(String) in type Invoice
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11311
    
  16

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 ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
There is no other constructor in this class.Thnx for the immediate replies!
Nick Petas
Ranch Hand

Joined: Jan 31, 2007
Posts: 38
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
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40

It compiles fine, with *no* errors when I tried it.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Which line does the error point to? (Just double-click on the error in the problems view.)


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to enter 2 parameters of the same type in a class constructor