Line 2: public static synchronized FactoryClass getInstance(String className)
Line 3: {
Line 4: //instance = null; (
Line 5: //only if 'instance' is == 'null', it creates a new instance
Line 6: if ( instance == null )
Line 7: {

Line 8: instance = new FactoryClass(className); // constructor call with single argument
Line 9: }

return instance;
}

Note: here in this code, when i change the className(input parameter), with the new class name, the instance is not getting 'null', instead it is holding the instance of the previous class. For this i have declared the instance as 'null', in the code(line number 4), within the constructor method... is it right way of coding.

You have coded a singleton pattern class. Only ONE instance of the class is supposed to be created.
What do you intend to happen?
The arg className does NOT have any influence on whether a new instance is created.