1. Using new keyword
2. Using clone()
It creates a copy of an existing object.
3. Using Class.forName()
If we know the name of the class and it has a public default constructor we can create an object in this way.
(MyObject) Class.forName("genius.MyObject").newInstance();
4. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.
MyClass object = (MyClass) inputStream.readObject(); |
Monday, 25 April 2016
How many ways to create an object ?
Labels:
Core Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.