Object array with constructor
I have a class project that requires a Symbol array. The parameters are:
Symbol class with constructor and methods equals and toString and a TestDriver class that declares the Symbol array and main. Here's what I have:
Code Java:
public class Symbol {
private String inputSymbol; //Instance variable
public Symbol(String sym){
inputSymbol = sym;
}
public boolean equals(Symbol sym){
return false;
}
public String toString(){
}
Code Java:
public class TestSymbols {
public static void main(String[] args) throws IOException {
Symbol[] sym = new Symbol[100];
sym[0] = new Symbol("Katie");
String tempText = sym[0].toString();
System.out.println(sym[0]);
System.out.println(tempText);
System.exit(0); //end program
}
}
The print statements are always null. What am I doing wrong that I cannot populate/access sym? How do I add and read an element at sym [i]?
Thanks for your halp.
Re: Object array with constructor
Does the code you've posted compile? The toString() method doesn't appear to return anything.
Please use code tags when posting your code: Java Forums - BB Code List
Re: Object array with constructor
Thank you for the quick reply. Resolved!!! toString needed to return the instance variable (I had it returning null). To summorize, type String, for example, is a class and when you type String. and get all the available options, those are the methods. By creating class Symbol, the methods in that class are associated with Symbol.
Re: Object array with constructor
(I had it returning null).
So why do you post code that is NOT the code with the problem?????