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 is a substitution variable?
What is an enumeration class?
Can we compare two strings in java?
What does a void function return?
What do you understand by synchronization?
Scenario: There are 1 to 100 numbers. Each number should be keep in the each column like from A column to Z column ie 1 to 26. From 27 to 52 should be in 2nd row in the excel sheet. This has to be continue till 100. How do you write Java program and what are various methods.
what is bytecode ?explain in detail and watz the difference between bytecode and machine code?
can write code for serialization ?
What is the exception hierarchy in java?
How many types of literals are there in JAVA?
Write a program for recursive Traverse?
Explain heap sort?