Answers were Sorted based on User's Feedback
Answer / ishaque
There are many ways to create an object in java. They are:
By new keyword
By newInstance() method
By clone() method
By factory method etc.
|Is This Answer Correct ?||15 Yes||1 No|
Answer / akshay
Object is created following ways
1.Using NEW operator
|Is This Answer Correct ?||7 Yes||1 No|
There are FIVE different ways to create objects in Java:
1. Using `new` keyword:
This is the most common way to create an object in Java. Almost 99% of objects are created in this way.
MyObject object = new MyObject();//normal way
2. By Using Factory Method:
RunTime rt=Runtime.getRunTime();//Static Factory Method
3. By Using Cloning Concept:
By using clone(), the clone() can be used to create a copy of an existing object.
MyObjectName anotherObject = new MyObjectName();
MyObjectName object = anotherObjectName.clone();//cloning Object
4. Using `Class.forName()`:
If we know the name of the class & if it has a public default constructor we can create an object in this way.
MyObjectName object = (MyObjectNmae) Class.forName("PackageName.ClassName").newInstance();
5. Using object deserialization:
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStreamName inStream = new ObjectInputStreamName(anInputStream );
MyObjectName object = (MyObjectNmae) inStream.readObject();
|Is This Answer Correct ?||2 Yes||0 No|
Answer / anu sownthariya rajakumari,isw
|Is This Answer Correct ?||0 Yes||0 No|
What is the purpose of the File class?
What does @override mean?
What is the maximum length of a url?
What is protected in java?
Hi friends, i am new to java. can you explain how java is secured.
Can you sort a string in java?
What is jit compiler in java?
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
What is main difference between variable and constant?
What are the steps involved to write rmi based programs?
What is numeric promotion?
What is the best definition for data?