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 object a data type?
What is the difference between applet and application?
How do I get a substring?
How can you make sure that your singleton class will always return single instance in multi-threaded environment?
What is overloading and overriding in java?
What is a for loop in java?
Which is easier netbeans or eclipse?
What are accessor methods in java?
What is ctrl m character?
what r advatages of websphere? & how to deploy?
What is the requirement of thread in java?
Compare java and python.
When throw keyword is used?
What is the default value of the local variables?
What is difference between static variable and global variable?