Hi
kathik prasad See the code below
interface Animal{}
class Elephant implements Animal{}
class Tiger implements Animal{}
public class Main
{
final static public void main(String[] args)
{
Animal animal = method(args[0]);
}
public static Animal method(String arg)
{
if(arg.equals("Vegie"))
return new Elephant();
else
return new Tiger();
}
}
Here which object to be created depends on the input from user..
And mostly
we use abstract classes and interfaces to have common parent type..Or to make use of
polymorphism..
Regards..