What is the diff between between Class.forname(""); and new Foo();

Questions by sachinTest

Showing Answers 1 - 3 of 3 Answers

chris

  • Aug 28th, 2006
 

Class.forName(className) returns a "Class" object for the class named "className" or throws a ClassNotFoundException if "className" cannot be found. A call to new Foo() will return a new instance of the class "Foo".

  Was this answer useful?  Yes

ambadas

  • Sep 8th, 2006
 

Class.forname("xxxx") will returns the xxxx object after the xxxx class is loaded otherwise it will throw the exception. But new Foo() will creates the object of Foo() when the if there is Foo class is available means it doesn't require the Foo class to be loaded

  Was this answer useful?  Yes

VTR Ravi Kumar

  • Sep 21st, 2006
 

If the class is not found in Class.forname("") then only a runtime exception is raised. But if foo() is not found a compile time exception occurs as well...

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions