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


Please Help Members By Posting Answers For Below Questions

What are peerless components in java programming?

585


What is the purpose of using the java bean?

570


What is void keyword?

675


Can you call a method on a null object?

563


Does java support function overloading, pointers, structures, unions or linked lists?

607






What is the constructor?

581


If a class is declared without any access modifiers, where may the class be accessed in java programming?

659


What is field name?

587


What is an example of declaration?

525


What do you know about java?

525


What is difference between this and super keyword?

519


Explain about fail safe iterators in java?

568


What is method overloading in java ?

560


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?

695


Explain the advantages of packages in java?

517