How can u create the Object of class Without using "New"
opertor?
Answers were Sorted based on User's Feedback
Answer / mohan reddy
In 3 ways we can able to create object without using "new"
operator.
1)Using a Static Factory Method
ABC.getInstance();
2)Using newInstance() method...
class A=(A)Class.forName("A").newInstance();
3)Using clone() method.
Is This Answer Correct ? | 38 Yes | 7 No |
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 |
Answer / seshu godavarthi
when the class is declared as static we can create an
object for the class without instantiating or without using
new operator...we can access the variables or methods in
the class by using the classname
Is This Answer Correct ? | 6 Yes | 1 No |
What does those terms actually mean included in the j.d.k i.6?
What is the difference between static method and instance method in Java?
0 Answers SwanSoft Technologies,
what is the collable collections in java?
If you do not want your class to be inherited by any other class. What would you do?
Can arraylist hold different types java?
How many types of design patterns are there?
what is the output??????? public class multireturn { public(int assign x ( int x) { if(4==x) { return 7; } else if (7=x+3) { return 6; } return 5; } }
How is it possible in java programming for two string objects with identical values not to be equal under the == operator?
How to Create A Wapper Class in core Java and Why are Use in java?
Explain the difference between runnable and callable interface in java?
What is the difference between java and .Net?
write a program that list all permutations of ABCDEF in which A appears before B?