Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2007, 10:34 PM
Member
 
Join Date: Aug 2007
Posts: 20
Rgfirefly24 is on a distinguished road
error with super.xxxxx
i'm attempting to create a child class that passes data to the parent class's method or constructor. I get the following error when compiling:
G:\Chair.java:54: cannot find symbol
symbol : method Item(int,float,java.lang.String)
location: class Item
super.Item(passchair, passchair_cost, passname);
^
1 error

Tool completed with exit code 1

this is the chair.java file:

Code:
import javax.swing.*; public class Chair extends Item{ private int chair1; private float chair1_cost; private String name; public Chair(){ } public Chair(int chair1, float chair1_cost, String name){ this.chair1 = chair1; this.chair1_cost = chair1_cost; this.name = name; this.passdata(chair1, chair1_cost, name); this.setchair1(super.getItemNum()); this.setchair1_cost(super.getCost()); this.setname(super.getManufacturersName()); } public void setchair1(int newchair1){ chair1 = newchair1; } public int getchair1(){ return chair1; } public void setchair1_cost(float newchair1_cost){ chair1_cost = newchair1_cost; } public float getchair1_cost(){ return chair1_cost; } public void setname(String newname){ name = newname; } public String getname(){ return name; } public void passdata(int passchair, float passchair_cost, String passname){ super.Item(passchair, passchair_cost, passname); } } and this is the Item.java file: import javax.swing.*; public class Item{ protected int item_number; protected float item_cost; protected String manufacturers_name; public boolean TF; public boolean TF1; /* default constructor */ Item(){ } Item(int item_number, float item_cost, String manufacturers_name){ this.item_number = item_number; this.item_cost = item_cost; this.manufacturers_name = manufacturers_name; this.setItemNum(item_number); this.setItemCost(item_cost); this.setManufacturersName(manufacturers_name); } public boolean isItemnum1(){ return TF; } public boolean isCost1(){ return TF1; } public int getItemNum(){ return item_number; } public float getCost(){ return item_cost; } public String getManufacturersName(){ return manufacturers_name; } public void setItemNum(int newitem_number){ if (newitem_number < 0){ TF = false; item_number = 0; } else { TF = true; item_number = newitem_number; } } public void setItemCost(float newitem_cost){ if (newitem_cost < 0){ TF1 = false; item_cost = 0; } else { TF1 = true; item_cost = newitem_cost; } } public void setManufacturersName(String newmanufacturers_name){ manufacturers_name = newmanufacturers_name; } }

Last edited by levent : 08-05-2007 at 10:51 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 09:13 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
Code:
public class ChairRx extends Item{ // Let the superclass keep these items. // Keep things here that pertain more // specifically to Chair and less to Item, ie, // member variables not shared by Item. // private int chair1; // private float chair1_cost; // private String name; public ChairRx(){ } public ChairRx(int chair1, float chair1_cost, String name){ // Send these values to the superclass. super(chair1, chair1_cost, name); } public String toString() { return "ChairRx[item_number:" + item_number + ", item_cost:" + item_cost + ", manufacturers_name:" + manufacturers_name + "]"; } public static void main(String[] args) { ChairRx chair1 = new ChairRx(1, 10.00f, "Allen"); System.out.println("chair1 = " + chair1); ChairRx chair2 = new ChairRx(2, 25f, "Thomas"); System.out.println("chair2 = " + chair2); System.out.println("chair1.getItemNum = " + chair1.getItemNum()); System.out.println("chair1.getCost = " + chair1.getCost()); System.out.println("chair1.getManufacturersName = " + chair1.getManufacturersName()); } } class Item{ protected int item_number; protected float item_cost; protected String manufacturers_name; public boolean TF; public boolean TF1; /* default constructor */ Item(){ } Item(int item_number, float item_cost, String manufacturers_name){ // Use this way of initializing member variables this.item_number = item_number; this.item_cost = item_cost; this.manufacturers_name = manufacturers_name; // or use this way. No need to use both. // this.setItemNum(item_number); // this.setItemCost(item_cost); // this.setManufacturersName(manufacturers_name); } //////// These methods are inherited by subclasses //////// public boolean isItemnum1(){ return TF; } public boolean isCost1(){ return TF1; } public int getItemNum(){ return item_number; } public float getCost(){ return item_cost; } public String getManufacturersName(){ return manufacturers_name; } public void setItemNum(int newitem_number){ if (newitem_number < 0){ TF = false; item_number = 0; } else { TF = true; item_number = newitem_number; } } public void setItemCost(float newitem_cost){ if (newitem_cost < 0){ TF1 = false; item_cost = 0; } else { TF1 = true; item_cost = newitem_cost; } } public void setManufacturersName(String newmanufacturers_name){ manufacturers_name = newmanufacturers_name; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Super CSV 1.20 JavaBean Java Announcements 0 11-27-2007 09:22 PM
Super CSV 1.15 JavaBean Java Announcements 0 10-16-2007 07:37 PM
Use super. or this. Marcus New To Java 1 07-05-2007 07:52 AM
difference between this and super mrark New To Java 1 06-27-2007 06:23 PM


All times are GMT +3. The time now is 06:41 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org