What is polymorphism, what is it for, and how is it used?

前端 未结 28 2732
南笙
南笙 2020-11-21 07:08

What is polymorphism, what is it for, and how is it used?

28条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 07:56

    If anybody says CUT to these people

    1. The Surgeon
    2. The Hair Stylist
    3. The Actor

    What will happen?

    • The Surgeon would begin to make an incision.
    • The Hair Stylist would begin to cut someone's hair.
    • The Actor would abruptly stop acting out of the current scene, awaiting directorial guidance.

    So above representation shows What is polymorphism (same name, different behavior) in OOP.

    If you are going for an interview and interviewer asks you tell/show a live example for polymorphism in the same room we are sitting at, say-

    Answer - Door / Windows

    Wondering How?

    Through Door / Window - a person can come, air can come, light can come, rain can come, etc.

    To understand it better and in a simple manner I used above example.. If you need reference for code follow above answers.

提交回复
热议问题