| Author |
Can someone spot an error here?
|
Xara Mithra
Greenhorn
Joined: Nov 17, 2003
Posts: 12
|
|
I took this partial prrogram from JavaRules Vol 2 : ------------------------------------------------ public class StringBuffer{ public StringBuffer() { this(16); } public StringBuffer(int length) { value = new char[length]; shared = false; } public StringBuffer(String str) { this(str.length() + 16); append(str); } public static void main(String args[]) { } } Errors : --------- StringBuffer.java:8: cannot resolve symbol symbol : variable value location: class StringBuffer value = new char[length]; ^ StringBuffer.java:9: cannot resolve symbol symbol : variable shared location: class StringBuffer shared = false; ^ StringBuffer.java:14: cannot resolve symbol symbol : method append (java.lang.String) location: class StringBuffer append(str); ^ 3 errors Suggest : Can someone suggest what to write in main() method. So I understand these constructors? Sorry if the questions are too silly
|
 |
Simon Klaiber
Greenhorn
Joined: Nov 13, 2003
Posts: 9
|
|
You have to declare the variables... If you want them local (what i don't think) use: and If you want them as instance variables (what I do think you want) declare them inside the class but outside the methods as and if you want to use You need a method called append that takes a String object as parameter: for example: or if you want to encapsulate the method within the constructors or other public methods. BTW when you use it does the same as but makes the code easier to read. Simon [ November 20, 2003: Message edited by: Simon Klaiber ] [ November 20, 2003: Message edited by: Simon Klaiber ]
|
 |
 |
|
|
subject: Can someone spot an error here?
|
|
|