class HelloWorld
{
public static void main
(String[] args
) {
Foo tmp = new Foo(10, 2);
Foo foo = (Foo)tmp.clone();
if (foo != null) {
System.
out.
println(foo.
getClass()); System.
out.
println("foo.p = " + foo.
getP()); System.
out.
println("foo.n = " + foo.
getN()); System.
out.
println("foo.mul = " + foo.
mul()); } else {
}
System.
out.
println(tmp.
equals(foo
));
}
int n;
int p;
Hoge() {
}
Hoge(int n, int p) {
this.n = n;
this.p = p;
}
try {
System.
out.
println(this.
getClass()); Hoge h = this.getClass().newInstance();
h.n = n;
h.p = p;
return h;
return null;
}
}
public int getN() {
return n;
}
public int getP() {
return p;
}
}
static class Foo extends Hoge {
Foo() {
}
Foo(int n, int p) {
super(n, p);
}
public int mul() {
return n * p;
}
}
}
Y2xhc3MgSGVsbG9Xb3JsZAp7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgCiAgICAgICAgRm9vIHRtcCA9IG5ldyBGb28oMTAsIDIpOwogICAgICAgIAogICAgICAgIEZvbyBmb28gPSAoRm9vKXRtcC5jbG9uZSgpOwogICAgICAgIAogICAgICAgIGlmIChmb28gIT0gbnVsbCkgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oZm9vLmdldENsYXNzKCkpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImZvby5wID0gIiArIGZvby5nZXRQKCkpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImZvby5uID0gIiArIGZvby5nZXROKCkpOwogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImZvby5tdWwgPSAiICsgZm9vLm11bCgpKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIk5VTEwhIik7CiAgICAgICAgfQoKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odG1wLmVxdWFscyhmb28pKTsKICAgICAgICAKICAgIH0KICAgIAogICAgc3RhdGljIGNsYXNzIEhvZ2UgaW1wbGVtZW50cyBDbG9uZWFibGUgewogICAgIAogICAgICAgIGludCBuOwogICAgICAgIGludCBwOwogICAgIAogICAgICAgIEhvZ2UoKSB7CiAgICAgICAgfQogICAgIAogICAgICAgIEhvZ2UoaW50IG4sIGludCBwKSB7CiAgICAgICAgICAgIHRoaXMubiA9IG47CiAgICAgICAgICAgIHRoaXMucCA9IHA7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHB1YmxpYyBPYmplY3QgY2xvbmUoKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGhpcy5nZXRDbGFzcygpKTsKICAgICAgICAgICAgICAgIEhvZ2UgaCA9IHRoaXMuZ2V0Q2xhc3MoKS5uZXdJbnN0YW5jZSgpOwogICAgICAgICAgICAgICAgaC5uID0gbjsKICAgICAgICAgICAgICAgIGgucCA9IHA7CiAgICAgICAgICAgICAgICByZXR1cm4gaDsKICAgICAgICAgICAgfSBjYXRjaCAoRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHB1YmxpYyBpbnQgZ2V0TigpIHsKICAgICAgICAgICAgcmV0dXJuIG47CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHB1YmxpYyBpbnQgZ2V0UCgpIHsKICAgICAgICAgICAgcmV0dXJuIHA7CiAgICAgICAgfQogICAgfQogICAgCiAgICBzdGF0aWMgY2xhc3MgRm9vIGV4dGVuZHMgSG9nZSB7CiAgICAgICAgCiAgICAgICAgRm9vKCkgewogICAgICAgIH0KICAgICAgICAKICAgICAgICBGb28oaW50IG4sIGludCBwKSB7CiAgICAgICAgICAgIHN1cGVyKG4sIHApOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgaW50IG11bCgpIHsKICAgICAgICAgICAgcmV0dXJuIG4gKiBwOwogICAgICAgIH0KICAgICAgICAKICAgIH0KfQo=