Knowledge Walls
John Peter
Pune, Maharashtra, India
What are the different ways to create an object in JAVA?
1. Create an object using "new" keyword
ClassName object = new ClassName();
2. Create instance using instance of a Class
ClassName obj1 = new ClassName();
ClassName obj2 = obj1.getClass().newInstance();
3. Cloning/Copying an object using clone() method
ClassName obj1 = new ClassName();
ClassName obj2 = obj1.clone();
4. Creating object using hardcoded Classname including package.
Object obj1 = Class.forName("").newInstance();
5. Assign serialized object stream to object, which is written by writeObject()
ObjectInputStream ois = new ObjectInputStream(InputStream Object);
ClassName obj1 = (ClassName) ois.readObject();
Next Topics
Next lessons of current book.
Computer software engineer articles of One day One Thing to Know
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details