• More than 1000 Questions
  • Short Tests for revision
  • New Questions added Daily
  • Search by Topic, Level, Frequency & Company
  • Actively Moderated by experienced developers

Search Java Interview Questions

Best Java Question Repository on web. Click Here

Java - Interview Questions and Answers on Class.forName

Q1.  Difference between loadClass and Class.forName ?

Ans. loadClass only loads the class but doesn't initialize the object whereas Class.forName initialize the object after loading it.

Q2.  Difference between static vs. dynamic class loading?
Ans. static loading - Classes are statically loaded with Java’s “new” operator.

dynamic class loading - Dynamic loading is a technique for programmatically invoking the functions of a class loader at run time.

Class.forName (Test className);

Q3.  What are different ways of object creation in Java ?

Ans. Using new operator - new xyzClass()
Using factory methods - xyzFactory.getInstance( )
Using newInstance( ) method - (Class.forName(“xyzClass”))emp.newInstance( )
By cloning an already available object - (xyzClass)obj1.clone( )

Q4.  Difference between new operator and Class.forName().newInstance() ?

Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class.

Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus