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
What is the difference between stream and buffer?
Does apple use java?
Can there be an abstract method without an abstract class?
Explain java thread life cycle.
What are the differences between c++ and java?
What does i ++ mean in Java?
Explain the importance of finally over return statement?
What is string and example?
What do you know about java?
What do you mean by boolean?
What is stream api in java8?
Explain about interthread communication and how it takes place in java?
What is the difference between yielding and sleeping?
Can you declare an interface method static?
Is void a data type in java?