There are at least four ways to create a new object:
1) Using new
1) Using new
Person obj = new Person();
2) Using clone
Person p = new Person(); Person obj = (Person)p.clone();
3) Using Class.forName(...)
Person obj2 = (Person) Class.forName("Person").newInstance();
4) De-serializing
InputStream instream = new FileInputStream("Person.ser"); ObjectInputStream in = new ObjectInputStream(instream); Person object = (Person) in.readObject();
If you know anyone who has started learning Java, why not help them out! Just share this post with them. Thanks for studying today!...
No comments:
Post a Comment