There are 2 different ways to create an object. a)By using
keyword "new" b)By using Class.forName
("className").newInstance();
What is the difference between these 2 methods.
Answer Posted / aslam
If we know the class name during the compile time, we must
use the keyword "new". because this creates much faster
than the second method. But if we get the class name only
on run time, we have to use Class.forName
("classNameAsArgument").newInstance(); Here we can pass the
class name as a string argument. We can't achieve this with
the keyword "new".
| Is This Answer Correct ? | 17 Yes | 0 No |
Post New Answer View All Answers
Is an object null?
What is keyset in java?
What is java command?
What is e java?
Is list ordered in java?
Explain the difference between static and dynamic binding in java?
Can a class be private?
Can you declare an interface method static?
Is math an abstract class in java?
What are scalar data types?
What is regex in java?
What are the methods available in a class?
Why does java not allow multiple public classes in a java file ?
How many types of classes are there in java?
Why we use protected in java?