class

A

Ah Ming

Hi!

I write the following code of java with the compilation error.
Would you mind helping to find the key problem? The error is shown as
following.

Shop.java:8: cannot resolve symbol
symbol : constructor Product (java.lang.String,double)
location: class Product
product[0]= new Product("Apple", 3.5);

Kai Ming

Product.java:
public class Product{
//Attribute
public String name;
public double price;

//Constructor
public void Product (String aName, double aPrice){
name = aName;
price = aPrice;
}

//getter/setter
void setProduct(){
Product("Apple", 3.5);
}
}

Shop.java:
public class Shop {

//attribute called product
public Product[] product=new Product[3];

//constructor
public Shop () {
product[0]= new Product("Apple", 3.5);
product[1]= new Product("Orange", 3);
product[2]= new Product("Pear", 2.5);
}

}
 
A

Andrew Thompson

public class Product{
//Attribute
public String name;
public double price;

//Constructor
public void Product (String aName, double aPrice){

A constructor has no return type.

public Product(String aName, double aPrice ) {
...

What you have is a public method called Product.

Please consider directing beginner questions to a group
better suited helping those learning the Java basics..
<http://www.physci.org/codes/javafaq.jsp#cljh>

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top