Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > class

Thread Tools


Ah Ming
Posts: n/a

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. cannot resolve symbol
symbol : constructor Product (java.lang.String,double)
location: class Product
product[0]= new Product("Apple", 3.5);

Kai Ming
public class Product{
public String name;
public double price;

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

void setProduct(){
Product("Apple", 3.5);
public class Shop {

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

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
Posts: n/a
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..


Andrew Thompson Web & IT Help Open-source software suite Science & Technology Images that escape the mundane
Reply With Quote

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