← Back to Polymorphism
Question 683
Polymorphic Factory From Input
Polymorphic Factory From Input
A factory method can return different subclasses through the same base type, chosen at runtime.Notificationis abstract withabstract string Format(string);EmailNotificationandSmsNotificationare complete. InNotificationFactory, finishCreate(string type)so it returns anEmailNotificationwhentypeisSmsNotificationotherwise. The tester reads the type and message from input. Do NOT write aMainmethod. For inputHellothe program prints the output shown in Expected Output. For inputsmsthenHiit prints: SMS: Hi
Expected Output:
Email: Hello= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Polymorphism
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.