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
What is string immutability?
What is == mean?
Explain the difference between abstract class and interface in java?
What are the differences between Java 1.0 and Java 2.0?
how many types of Inheritance?
What is an inner class in java?
What is sortedmap in java?
What is the purpose of using java.lang.class class?
What is the purpose of the strictfp keyword?
What is the difference between super class & sub class?
Explain thread in java?
What class allows you to read objects directly from a stream?
What is difference between identifier and variable?
What is tochararray in java?
Who is founder of java?