Apologies if this has been asked before however I have not been able to find an answer that really explains how to achieve or get around my problem.

---

The issue I am facing is how to split up code into separate classes without asking anything about the first object. For example the most common explanation of polymorphism uses:

```
abstract class Animal {
    abstract String talk();
}

class Cat extends Animal {
    String talk() {
        return "Meow!";
    }
}

class Dog extends Animal {
    String talk() {
        return "Woof!";
    }
}

void letsHear(final Animal a) {
    println(a.talk());
}

int main() {
    letsHear(new Cat());
    letsHear(new Dog());
}

```

However, what if I dint know that I wanted to create a new Dog and a new Cat. If this was a form that a user fills in and they could choose a cat or dog. Currently I would write the following solution to the problem:

```
abstract class Animal {
    abstract String talk();
}

class Cat extends Animal {
    String talk() {
        return "Meow!";
    }
}

class Dog extends Animal {
    String talk() {
        return "Woof!";
    }
}

void letsHear(final Animal a) {
    println(a.talk());
}

int main() {
    string userInput = Console.ReadLine();
    switch(userInput){
      case "Cat": 
         letsHear(new Cat());
         break;
      case "Dog":
        letsHear(new Dog());
        break;
    }
}

```

There must be a better solution than using a case statement to find out which ID the user selected to create the class. Please let me know if the question does not make sense or this is probably the best way of solving this issue. I know my code does not compile or work but this is more of an architecture question rather than specific code that works.