Results 1 to 2 of 2
- 01-23-2013, 04:23 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 35
- Rep Power
- 0
subclass arguments to superclass variables
SOLVED!
Hi, I am making a chess piece like this:
Piece wKing = new King("King", 'w');
Piece is superclass to King. Piece has variables "String Name" and "char Color".
Piece:
King:Java Code:public String Name; public char Color; public Piece(String iName, char iColor) { Name = inName; Color = inColor; }
First, do I have to have the variables in Piece protected/public for this?Java Code:public class King extends Piece { public King(String iName, char iColor) { super(Name, Color); } }
Second, why do I get "cannot reference Name before supertype constructor has been called" on both when I have them as protected in the superclass?Last edited by Gatsu; 01-23-2013 at 04:49 PM.
- 01-23-2013, 04:48 PM #2
Member
- Join Date
- Dec 2012
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
How to store user input from subclass into variables from superclass
By mc54321 in forum New To JavaReplies: 7Last Post: 11-04-2012, 11:04 PM -
Override a superclass's methods with a subclass
By zach&kody in forum New To JavaReplies: 7Last Post: 05-24-2011, 02:50 PM -
Using superclass fields in subclass method
By lonegreyride in forum New To JavaReplies: 12Last Post: 11-17-2010, 01:21 PM -
superclass and subclass
By mr idiot in forum New To JavaReplies: 19Last Post: 01-03-2009, 07:29 AM -
which class is superclass and subclass?
By java_fun2007 in forum New To JavaReplies: 0Last Post: 12-11-2007, 08:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks