Hello. I fixed your code.
[code]
/*
* Enterprise quality implementation of one plus one
* Copyright (C) 2010 /prog/ <
http://dis.4chan.org/prog/>;
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License v2
* (version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, refer to the following URL:
*
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
package prog;
import java.math.BigInteger;
class Number {
private Integer m_number;
Number(Integer m_number) {
this.m_number = m_number;
}
Number() {
this.m_number = 0;
}
Integer getInteger() {
return m_number;
}
Number add(Number a) {
return new Number(new Integer(a.getInteger().intValue()
+ getInteger().intValue()));
}
@Override
public String toString() {
return getInteger().toString();
}
}
class One extends Number {
static Number cached_one = new Number(Integer.parseInt(BigInteger.ONE.toString())); //cached for efficiency
static Number createNumberOne() {
return cached_one;
}
}
public class Main {
public static void main(String[] args) {
Number result = One.createNumberOne().add(One.createNumberOne());
System.out.println(result); //result.toString() is invoked here
}
}