class

Discussion in 'Java' started by Ah Ming, Dec 27, 2004.

  1. Ah Ming

    Ah Ming Guest

    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);
    }

    }
     
    Ah Ming, Dec 27, 2004
    #1
    1. Advertising

  2. On 27 Dec 2004 04:19:58 -0800, Ah Ming wrote:

    > 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

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
     
    Andrew Thompson, Dec 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cyril
    Replies:
    2
    Views:
    3,868
    cyril
    Aug 25, 2004
  2. Purush
    Replies:
    4
    Views:
    1,662
    Purush Rudrakshala
    Apr 13, 2005
  3. E11
    Replies:
    1
    Views:
    4,781
    Thomas Weidenfeller
    Oct 12, 2005
  4. christopher diggins
    Replies:
    16
    Views:
    756
    Pete Becker
    May 4, 2005
  5. Joseph Turian
    Replies:
    5
    Views:
    594
Loading...

Share This Page