1. Newsomething obj=new something (); 2. Clonecreates a new object instance based on an existing object instance. only classes that implement the Java.lang.Cloneable interface are limited. Otherwise, a clonenotsupportedexception exception is thrown.
As follows, another object instance can be established based on the current object itself (but not with the construction method).
class Something{//codesPublic Something Createclone () {Something obj=null;Try {obj= (Something) clone (); }catch (clonenotsupportedexception e) {E.printstacktrack (); }return obj; }}3, Newinstanceusing the Newinstance method of the Java.lang.Class class, an object instance of the class represented by this class can be built according to the object instance of class (call the constructor without parameters)as follows:Someobj.getclass (). newinstance ();//or Next CodesSomething obj=class.forname (Something). Newintance ();It is important to note that the Newiinstance method runs out of instantiationexception or illegalacsessexception exceptions, so This exception should be caught in the catch statement block.
Several methods of building examples in Java