How can u create the Object of class Without using "New"
opertor?
Answer Posted / giridhar gangapatnam
There are 4 ways to create object:
1.using new operator
Employee obj=new Employee();
Except this one
2.using factory methods
NumberFormat obj=NumberFormat.getNumberInstance();
3.using newInstance() method
Class c=Class.forName("Employee");
Employee obj=(Employee)c.newInstance();
or we can write these two lines as a single line
Employee obj=
(Employee)Class.forName("Employee").newInstance();
4.By cloning
Employee obj1=new Employee();
Employee obj2=(Employee)obj1.clone();
Is This Answer Correct ? | 20 Yes | 4 No |
Post New Answer View All Answers
Explain parallel processing in java8?
What checkbox method allows you to tell if a checkbox is checked?
Can you call a method in a method?
What is difference between overloading and overriding in java?
How does the java compiler work?
What is immutable data?
What is rmi and steps involved in developing an rmi object?
Can anonymous class have constructor?
How to store image in arraylist in java?
How can we find the actual size of an object on the heap?
What is final keyword in java?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?
Can we extend immutable class?
What are the different types of multitasking?
Can constructor return value?