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.

Answers were Sorted based on User's Feedback



There are 2 different ways to create an object. a)By using keyword "new" b)By using Clas..

Answer / 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

There are 2 different ways to create an object. a)By using keyword "new" b)By using Clas..

Answer / qim2010

Java’s “new” operator is used to load the class statically.

class MyClass {
public static void main(String args[]) {
Car c = new Car();
}
}

Class.forName (String className); is used for dynamic class
loading. The string className can be supplied dynamically at
run time. Once the class is dynamically loaded the following
method returns an instance of the loaded class. It’s just
like creating a class object with no arguments.

class.newInstance (); //A non-static method, which creates
an instance of a
//class (i.e. creates an object).

Is This Answer Correct ?    4 Yes 0 No

There are 2 different ways to create an object. a)By using keyword "new" b)By using Clas..

Answer / ratnesh gupta

the first way to create an object is 'class name object
name'and the secondone is classNameAsArgument").newInstance
();

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More Core Java Interview Questions

What is the difference between overloading and overriding a function?

13 Answers   eG Innovations, Infosys, TCS,


What is overloading and overriding in java?

0 Answers  


Is alive and join method in java?

0 Answers  


What is hashmap in java?

0 Answers  


Explain the difference between getAppletInfo and getParameterInfo?

1 Answers  






What is rmi and steps involved in developing an rmi object?

0 Answers  


"We cannot create an object of interface but we can create a variable of it". Discuss the statement with the help of an example. (Plz help us to provide immediately.)

3 Answers  


What are the topics in advance java?

0 Answers  


What is string literal in java?

0 Answers  


What is the Dictionary class?

1 Answers  


Is java hard to learn?

0 Answers  


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

0 Answers   Genpact,


Categories