Technical questions and Answers
Tags: #Java, #JavaInterview, #InterviewQuestions
- How to create an Object in Java without using new() function ?
There are different ways in Java to allow instantiate an Object, few of them are listed below
- newInstance() method of Class Class class = Class.forName(MyClass); MyClass myObject = (Object) class.newInstance();
- clone() method of Object class MyClass newObject = myObject.clone();
- Deserialization of any Object ObjectInputStream ois = new ObjectInputStream(System.in); MyClass newObject = ois.readObject(); .