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
How many bits is a 64 bit byte?
What is a void in java?
What methodology can be employed to locate substrings inside a string?
What is keyword in oop?
What is constructor chaining and how is it achieved in java?
Why char array is preferred over string for storing password?
How to add menushortcut to menu item?
What is the difference between heap and stack memory?
Which is better stringbuffer or stringbuilder?
What is the null?
How do you escape in java?
What comes to mind when someone mentions a shallow copy in java?
Difference between static binding and dynamic binding?
How to implement an arraylist in java?
Is it possible to write a regular expression to check if string is a number?