I tried getting the answer and finally found the solution.
(INSTEAD OF THE IF _ ELSE WE NEED TO REPLACE THE FOLLWOING CODE)
Class<?> clazz = Class.forName("PizzaTrail." + PType);
Object instance = clazz.newInstance();
p = (Pizza) instance;
return (p);
the above code will resolve the issue of writing the if else and reflection will help calling the class dynamically.