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


Please Help Members By Posting Answers For Below Questions

Explain parallel processing in java8?

630


What checkbox method allows you to tell if a checkbox is checked?

531


Can you call a method in a method?

525


What is difference between overloading and overriding in java?

523


How does the java compiler work?

523






What is immutable data?

574


What is rmi and steps involved in developing an rmi object?

559


Can anonymous class have constructor?

548


How to store image in arraylist in java?

505


How can we find the actual size of an object on the heap?

800


What is final keyword in java?

547


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?

514


Can we extend immutable class?

523


What are the different types of multitasking?

648


Can constructor return value?

507