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
When is the finalize() called?
Is java free for businesses?
What is the inheritance?
What is meant by singleton class?
What mechanism does java use for memory management?
What do you mean by scope of variable?
What will happen if a thrown exception is not handled?
What is pangram in java?
Can we override constructors in java?
What is javac_g?
What is java in simple terms?
What is classname class in java?
What is the purpose of a volatile variable?
How do you write a good declaration?
What are different types of classloaders?