| Author |
Return type required
|
Nick Harms
Ranch Hand
Joined: Mar 06, 2010
Posts: 44
|
|
This public Retailitem() is giving me this error, not sure why, to the naked eye it looks just like my example, probably a simple fixed.
Says invalid method declaration return type required,
This is a class a demo uses.
|
 |
ahamed irshad
Ranch Hand
Joined: Feb 26, 2010
Posts: 31
|
|
|
it should be capital i (I)in Retailitem.plesae make change in the constructor.
|
You can do anything, but not everything
|
 |
Nick Harms
Ranch Hand
Joined: Mar 06, 2010
Posts: 44
|
|
Ok now its saying cannot find symbol - class item in the demo. on the item one = new RetailItem(); line. Why is that? It matches the class name.
|
 |
Nick Harms
Ranch Hand
Joined: Mar 06, 2010
Posts: 44
|
|
|
Never mind I got it, should be RetailItem one= new RetailItem();
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Nick Harms wrote:Never mind I got it, should be RetailItem one= new RetailItem();
or *may be* you forget to implements *Item* interface . and,
remember : Constructor name must be same as class name
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
Nick,
Why do you have an empty constructor? Does it ever make sense to have an item with no information in this program?
You can use the overloaded constructor how it's supposed to and get rid of the setter method calls in your demo class. if it's a requirement to use the setter methods, you can use a
inside the overloaded constructor.
|
When you do things right, people won't be sure you've done anything at all.
|
 |
Saul Groene
Greenhorn
Joined: Apr 02, 2010
Posts: 2
|
|
#
# public double getUnitsOnHand()
# {
# return UnitsOnHand;
# }
should have an 'int' return type not a 'double'
|
Late
|
 |
Saul Groene
Greenhorn
Joined: Apr 02, 2010
Posts: 2
|
|
# //Display object 1 info
# System.out.println(" Item 1 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + one.getdescription());
# System.out.println("Units on hand: " + one.UnitsOnHand());
# System.out.println("Price: " + one.Price);
#
# //Display object 2 info
# System.out.println(" Item 2 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + two.getdescription());
# System.out.println("Units on hand: " + two.UnitsOnHand());
# System.out.println("Price: " + two.Price);
#
# //Display object 3 info
# System.out.println(" Item 3 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + three.getdescription());
# System.out.println("Units on hand: " + three.UnitsOnHand());
# System.out.println("Price: " + three.Price);
#
The bolded method calls above should be the 'getter' methods ie... three.getUnitsOnHand() instead of what is there..
|
 |
Janeice DelVecchio
Saloon Keeper
Joined: Sep 14, 2009
Posts: 1611
|
|
Saul,
Welcome to Java Ranch!
Please remember to use code tags... it helps format the code to make it easier to read
Thanks
|
 |
 |
|
|
subject: Return type required
|
|
|