Unless the current object does not implement java.lang.Cloneable
There is no error when your program runs directly, and it is correct under JDK1.31.41.51.6.
After reading the specification of java, theoretically any JDK should implement Object.clone ().
On the other hand, if you want to generate your own NullPointerException, you must let clone () return null, so there are only two possibilities: Object.clone () returns null or throws an exception.
Then it is inferred that the Account object does not implement java.lang.Cloneable!
So I guess in the same directory of your program, there is also a Cloneable.java who defines a customized Cloneable, or the following passage is missing from this program:
Interface can be cloned {
Public object clone ();
}
I tried that if there is a customized clone, the compiler will not think that the Account class implements java.lang.clone, so Object.clone () will throw an exception.