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
Are arrays immutable in java?
How do you initialize an arraylist in java?
What are thread safe functions?
How do you use compareto in java?
Is empty string in java?
What is jvm? How its run?
Mention the default values of all the elements of an array defined as an instance variable.
What is the difference between serializable and externalizable interfaces?
How many JVMs can run on a single machine and what is the meaning of Just-In-Time (JIT) compiler?
What is use of static in java?
What is definition and declaration?
In which language java is written?
What is the null?
Do I need java on my computer?
What is keyword in oop?