Suppose that I have a movie theater registration system.
And that I have a parent Customer class and a child MinorCustomer class.
MinorCustomer has a isAuthorized() method, which is not present in Customer, that returns true or false, meant to be called if the selected movie is not for unaccompanied minors
Now, when instantiating the classes to store the information in a data structure (whichever), I run into the issue that I cannot call isAuthorized() in the event that the client is a minor.
This is all hypothetical so there's no program with this code, but assuming the case would be
Customer cust = new Customer()
if(cust.getAge() < 18) {
cust = (MinorCustomer) cust;
cust.isAuthorized();
}
However, that code would not be valid, since it would still consider cust to be an instance of Customer, not MinorCustomer. I know that I could simply use an if statement to determine if I want to create a new instance of Customer/Minor depending on the age, but I'd like to take advantage of polymorphism to seamlessly change the type without having to write more rigid code.