How to create an instance of a class without using "new"
operator? Plz help me out properly.Thank u.
Answers were Sorted based on User's Feedback
Answer / saravanan p
By using Class d=Class.forName("className");
Object obj=c.newInstance();
| Is This Answer Correct ? | 77 Yes | 4 No |
Answer / b s vidyasagar reddy
three types
1.using factory methods
NumberFormat obj = NumberFormat.getNumberInstance();
2. using newInstance() method
class c = class.forName("Employee");
Employee obj = c.newInstance();
3. using coloning:
coloning is a way to create Bitwise exactcopy of an
existing object
Employee e2=e1.clone();
| Is This Answer Correct ? | 32 Yes | 4 No |
Answer / satchidananda.lanka
Dynamic loading is a technique for programmatically
invoking the functions of a class loader at run time.
Let us look at how to load classes dynamically.
Class.forName (String className); //static method which
returns a Class
The above static method returns the class object associated
with the class name.
The string className can be supplied dynamically at run
time.
Once the class is dynamically loaded the following method
returns an instance of the loaded class. It’s just like
creating a class object with no
arguments.
class.newInstance (); //A non-static method, which creates
an instance of a
//class (i.e. creates an object).
Example as shown below ....
Test test = null ;
String myClassName = "com.test.DynamicLoadingClass" ;
Class testClass = Class.forName(myClassName) ;
test = (Test) testClass.newInstance();
| Is This Answer Correct ? | 10 Yes | 3 No |
Answer / xxxx
with out new operater we can create object. Because the
String varible is taken as an object in java, which is
created with out new operater.
ex.
String str="xxxx";
| Is This Answer Correct ? | 8 Yes | 3 No |
Answer / eswar
yes ....Class is a class which creates object
dynamically.....
| Is This Answer Correct ? | 10 Yes | 7 No |
Answer / prakash sah
This is happening using reflection. Read reflection in java
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / abhishek thakur
1. Four Ways of Object creation
i)Using "new" operator
ii)Using newInstance Method in Class.forName(class name)
iii)in case of deserialisation
iv)using clone
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vaibhav
Serialization and then deserialization will create a new
object without using "new" operator.
| Is This Answer Correct ? | 1 Yes | 3 No |
Answer / arun kumar rout
In java without using new you can not create instance of a
class.
| Is This Answer Correct ? | 16 Yes | 66 No |
What is the difference between the boolean & operator and the && operator in java programming?
how to know the total memory occupied by the objects in the ArrayList(Array list may contain duplicate objects)
What is meant by object oriented programming – oop?
I need some details about an employee. i have only the employee id in my presentation layer(JSP).I entered that ID and click "Show Details" Button. Question is how the JSP pass that id to Controller layer and DAO and what mechanism we are using to retrive data from DB and how the data passed to JSP as a Output. Please explain in detail.
Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example
Explain pass by reference and pass by value?
Is java programming easy?
Sample code to retrieve objects from HashMap in sorted ascending order?
What is the difference between overriding and overloading in OOPS.
0 Answers Axtria, ITC Indian Tobacco Company,
What is floor math?
What is composition in java?
What are the advantages of defining packages in java?