Self Test Java -1
Yesterday, one of my colleague casually mentioned something while having lunch together. This is what he said “I am having a class in jar” On which I can do
Class.foName("fully qualified class name");
But, I am not able to do
clazz.newInstance();
The question stuck in my mind. But instead of going ususal root of opening a google box and tamly looking for answer I thought to self test me too. It should be easy pick and I got it bang on target except for the Exception names and exact jargon of the words. One should not be so hard on himself.
Quotuing from javadoc
IllegalAccessException - if the class or its nullary constructor is not accessible. InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason. ExceptionInInitializerError - if the initialization provoked by this method fails. SecurityException - if there is no permission to create a new instance.
Now this gonna be my new questions in the interviews I take. M gonna have some fun.