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 are peerless components in java programming?
What is the purpose of using the java bean?
What is void keyword?
Can you call a method on a null object?
Does java support function overloading, pointers, structures, unions or linked lists?
What is the constructor?
If a class is declared without any access modifiers, where may the class be accessed in java programming?
What is field name?
What is an example of declaration?
What do you know about java?
What is difference between this and super keyword?
Explain about fail safe iterators in java?
What is method overloading in java ?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?
Explain the advantages of packages in java?