How can we create a object of a class without using new
operator.
Answer / mamatha
There are different ways to create objects in java:
1. Using new keyword
This is the most common way to create an object in java.
MyObject object = new MyObject();
2. Using Class.forName()
MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();
3. Using clone()
The clone() can be used to create a copy of an existing object.
MyObject anotherObject = new MyObject();
MyObject object = anotherObject.clone();
4. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();
5.By using getInstance();
| Is This Answer Correct ? | 38 Yes | 8 No |
what is the use of pojo (plain old java objects)? how it is interact with crystal reports? pls urgent
Can a static class implement an interface?
Is there any need to import java.lang package?
Are maps ordered java?
What is string and example?
Is it possible to make an array volatile?
Can we catch more than one exception in single catch block?
Describe what a thread-local variable is in java?
What is array length?
What are different types of constants?
Given a singly linked list, how will you print out its contents in the reverse order? Can you do it with consuming any extra space?
0 Answers Akamai Technologies,
1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?