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 ststic with example
What does java stand for?
What is string and example?
What is static data type in java?
Can we create our own daemon thread?
What differences exist between iterator and listiterator?
What is the use of pattern in java?
What is overriding in java?
What is the byte range?
What is data type example?
What is jpa specification?
What is the difference between inheritance and encapsulation?
What is the difference between an inner class and a sub-class?
Can you declare the main method as final?
How to sort array of 0 and 1 in java?