Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > class

Reply
Thread Tools

class

 
 
Ah Ming
Guest
Posts: n/a
 
      12-27-2004
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);
}

}
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-27-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments