C++ OOP - What is polymorphism in programming? (simple example)

Sdílet
Vložit
  • čas přidán 29. 06. 2024
  • 📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    The word "polymorphism" means to have many forms.
    Polymorphism usually occurs when we have multiple classes that are related by inheritance. Because of this, two derived classes can define a method that has the same name, but the different implementation (behavior)
    In this video, I'm providing a simple explanation and example of what I mentioned above.
    This is a very understandable and simple explanation, that I found on the internet, and I want to share it with you:
    If you ask a question like "What is a set?" in the forum topic "Tennis", you'll get one answer and if the forum topic is "Data structures" you'll get an entirely different answer. That's because the people who read these two topics process the same question in different ways. This is basically what polymorphism does!
    👉 Download Visual Assist here: bit.ly/VisualAssistDownload
    (Improves Visual Studio experience by quickly identifying and fixing code errors)
    ☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. You can use the link below to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
    However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
    C++ Object-Oriented Programming playlist:
    • C++ OOP - Introduction... - Introduction to OOP
    • C++ OOP (2020) - What ... - Constructors and class methods
    • C++ OOP - What is enca... - Encapsulation
    • C++ OOP - What is inhe... - Inheritance
    C++ for beginners course: • C++ FOR BEGINNERS (202...
    C++ functions course:
    • C++ FUNCTIONS (2020) -...
    Follow me on other platforms:
    Instagram 📸 - / truecodebeauty
    Twitter 🐦- / truecodebeauty
    ******Initial code is available in COMMENTS and on TrueCodeBeauty GIT******
    github.com/TrueCodeBeauty/Pol...
  • Věda a technologie

Komentáře • 179

  • @CodeBeauty
    @CodeBeauty  Před 3 lety +29

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    #include
    #include
    using namespace std;
    class CZcamsChannel {
    private:
    string Name;
    int SubscribersCount;
    list PublishedVideoTitles;
    protected:
    string OwnerName;
    public:
    CZcamsChannel(string name, string ownerName) {
    Name = name;
    OwnerName = ownerName;
    SubscribersCount = 0;
    }
    void GetInfo() {
    cout

    • @sunilkumar-ft3nk
      @sunilkumar-ft3nk Před 3 lety +1

      What is the use of system (pause);.

    • @dasp125
      @dasp125 Před 3 lety +4

      @@sunilkumar-ft3nk pauses the program so it doesn’t display the directory address, exited with code 0 and press any key in the console after your programs output.

    • @sunilkumar-ft3nk
      @sunilkumar-ft3nk Před 3 lety

      @@dasp125 thank 👍👍

    • @ManMartin
      @ManMartin Před 3 lety

      Why it is called protected instead shared for example? Cause it is a property shared by all the objects crested frm the origen class. I dont undestand the names, like virtual.

  • @olivertwist8996
    @olivertwist8996 Před 2 lety +7

    This is honestly the best conetnt on YT for learning c++. My professor is completely useless and makes everything harder. Sometimes I spend 3 hours trying to understand a concept, then I find one fo your videos and I understand it instantly.
    P.S. When I watch your videos I never skip the ads but I let them run for as long as they run. I know that adsense pays youtubers more when ads are watched in full (or something like that :D ), anyway, THANK YOU!

  • @legolas5684
    @legolas5684 Před 3 lety +16

    please keep making videos!
    A brighter future waits you!

  • @mytechnotalent
    @mytechnotalent Před 3 lety +20

    Like the step-by-step breakdown this is a tough subject and you made it quite easy. Well done Saldina!

  • @jesusguerrero6916
    @jesusguerrero6916 Před 2 lety +3

    I'm a student's software engineer, and your videos are very helpfully to begin in C++ OPP, thanks for this content, I´m sure You help more than one person.
    Greetings from Mexico !!

  • @connelly6375
    @connelly6375 Před 3 lety +10

    great series, I have been doing C development for a long time and have always been intimidated by C++ but am loving it now!

  • @trueascendant8733
    @trueascendant8733 Před 3 lety +12

    Very much appreciate your time and energy you put into your video’s I’m still an absolute beginner, could you please do a tutorial on complete beginners for just C programming language, I love 💓 the way you teach you have the best videos on c++ that I’ve seen so far thank you x

  • @sayantanpaul6174
    @sayantanpaul6174 Před 3 lety +4

    Hey Saldina, thank you for providing such great C++ content. Very helpful for non-cs students to enter into programming. Please keep posting more videos. THANK YOU CODE BEAUTY !!😊

  • @dalerobinson3091
    @dalerobinson3091 Před 3 lety +18

    Hello Saldina. Your videos are very well done, and informative. Would you make a video explaining the 'Copy Constructor' when, and why it is used and needed? Thanks in advance.

  • @humanR14k
    @humanR14k Před rokem +5

    For people who didn't understand why Saldina used the pointer at the end of the video, well, I will explain the difference.
    The only limitation in using *yt1 and *yt2 instead of cookingYt and singersYt is that both *yt1 and *yt2 are of type CZcamsChannel* and therefore we can only use these pointers to refer to the members that cookingYT and singersYT inherit from CZcamsChannel. so if we were to call the private function from these derived class (The Function made in these classes), we would use "cookingYT or SingersYT" instead of *yt1 and *yt2.
    thx 😗

  • @pgallovich
    @pgallovich Před 3 lety +3

    I’m so glad I followed you from Brads channel. Love this content! So important for me at this time. Thank you!

  • @rif5164
    @rif5164 Před rokem

    You make my life easy! Thanks, Saldina!

  • @BetulKaplan
    @BetulKaplan Před 3 lety +4

    your video layout is helping me to understand a lot and the way you explain is very clear. keep it up!

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +3

      I'm happy to help, thanks! 🤗

  • @scalemodelsworld
    @scalemodelsworld Před 3 lety +7

    "I'm going to copy that, so that I don't make a typo"
    Introduces a typo with the copy :))
    Nice and informative videos, btw :)

  • @monoman4083
    @monoman4083 Před 3 lety +4

    Another great video. Many thanks..

  • @createrankit
    @createrankit Před 3 lety +3

    Great video lectures, hope you teach development part in c++ .

  • @kamceksej5524
    @kamceksej5524 Před měsícem

    beautiful video, very helpful, love it.

  • @kwayssa
    @kwayssa Před 3 lety +3

    Making the pointer type a base Class type, enables the pointer to only access the functions in that base class only, but making the pointer type a derived class type, enables the pointer to access functions in both classes, base class & that derived class..

    • @jvsnyc
      @jvsnyc Před 3 lety +1

      I am not sure, but I normally would only use the term polymorphism to refer to when a base class method gets overridden in one or more derived classes, and calls to that method defined in the base class "automagically" get the derived class behavior due to being defined as virtual in the base class thru the use of VTables. While it is true that the derived class members can also add new methods that aren't in the base class, unless the overridden methods call these in the derived class, that isn't using the base class polymorphically. In Java, all of the methods of a class are 'virtual' by default, placed in a VTable, and get this overriding behavior automatically, unless marked 'final' (Java doesn't even have a virtual keyword), but C++ doesn't do this automatically.
      Had she been calling ->practice() thru a base class pointer then this would have been using polymorphism, but that wouldn't even work here unless it was defined in the base class, perhaps as abstract, and virtual. Checking this now. Oops. Visual Studio wants an update, I'll be back after the reboot!

  • @aw230012
    @aw230012 Před rokem +12

    It's a good demonstration of polymorphism but you can't demonstrate true polymorphism without using the virtual keyword for dynamic binding. A better example would be to have the Practice function defined in the CZcamsChannel class as virtual or pure virtual, then override the Practice function in the child classes. Now, you can use Liskov Substitution to store the child classes as their parent, and still invoke the Practice method with polymorphism due to Practice being defined as virtual or pure virtual. I love your C++ series and thought I'd give some feedback on this one. I forward my students to your page all the time!

    • @mes2009
      @mes2009 Před 5 měsíci

      Continue Playlist u find what u talk about

  • @1maruf
    @1maruf Před 3 lety +1

    *much-obliged, Sister*

  • @BrunoAlves-tx4gs
    @BrunoAlves-tx4gs Před 3 lety +1

    Great video. Muito bom, execelente didatica.

  • @naderhumood1199
    @naderhumood1199 Před 2 lety +1

    Amazing channel......Thanks v much.

  • @jamesperih9658
    @jamesperih9658 Před 3 lety +14

    Wouldn't it be polymorphism if the base class had a .Practice method, but the derived classes implemented them differently?

    • @jimena6194
      @jimena6194 Před 2 lety +1

      thats polymorphism as well she has an example of that at the end of her video explaining virtual functions

  • @gehngis
    @gehngis Před 3 lety +12

    That is not polymorphism.
    I mean `CookingCZcamsChannel` has a single function named `Practice`, so their is no need to invoke polymorphism to call `cookingCZcamsChannel->Practice()`.
    Same thing for `SingersCZcamsChannel`.
    So in the end you end up with 2 functions that does not have the same full name: CookingCZcamsChannel::Practice and SingersCZcamsChannel::Practice.
    It is not polymorphism, it is just scoping.
    Casting a pointer of a derived class to a base class is not polymorphism.
    Calling a function a the base class (CheckAnanlytics) through pointer to the base class is still not polymorphism, even if the pointer points to an instance of the derived class.
    To demonstrate polymorphism, you need examples where you are missing a piece of information at the call site.
    You could have done:
    1. Have multiple functions with same name (and scope) but different parameters. This could be done by introducing `CookingCZcamsChannel::Practice(int effort)` and then when calling `cookingCZcamsChannel->Practice()` you effectively use polymorphism because the compiler has to decide if you are calling `CookingCZcamsChannel::Practice(int effort)` or `CookingCZcamsChannel::Practice()`.
    2. Make Practice() a virtual function *and* call it through pointer to the base class.
    class CZcamsChannel {
    ...
    virtual void Practice() = 0;
    ...
    }
    class CookingCZcamsChannel {
    ...
    void Practice() override;
    ...
    }
    CZcamsChannel *channel = new CookingCZcamsChannel;
    channel->Practice();
    3. Use templates and demonstrate polymorphism without inheritance.
    template
    void call_practice(T &channel) {
    channel.Practice();
    }

    • @diezgan
      @diezgan Před 3 lety +3

      I agree - without a virtual function (pure or not) in a base class and its overriding in a derived class(es), there is no dynamic polymorphism.

    • @kotinakarwak7857
      @kotinakarwak7857 Před 3 lety

      Tutor added (simple example) in title and hope she adds the features you mention above in the upcoming lesson to cement the knowledge to us beginners.
      Thanks for pointing this out too since reading through your suggestion easily explains what I have learnt so far and where I should go to next.

    • @jamesperih9658
      @jamesperih9658 Před 3 lety +2

      I get you on #2 and #3, but either #1 you meant CookingCZcamsChannel() and the base class CZcamsChannel()... or, aren't you just describing overloading?

    • @gehngis
      @gehngis Před 3 lety +2

      @@jamesperih9658 Yes, #1 is function overloading. But function overloading is also a subtype of polymorphism, named "ad hoc polymorphism" (en.wikipedia.org/wiki/Ad_hoc_polymorphism).
      I agree though that in day to day developer talks, polymorphism is not used to describe overloading.

    • @jvsnyc
      @jvsnyc Před 3 lety

      @@gehngis I strongly agree. Some pedants describe overloading as compile-time-polymorphism or early binding. Many of these pedants are brilliant, and have much to teach me, so I have taken to referring to overloading as compile-time-polymorphism or early-binding polymorphism, but I did OOPS for years without ever describing overloading as polymorphism, we always meant the virtual-method-in-base-class getting overridden behavior via. VTable as the 'simple' definition of polymorphism.
      What she shows is nice, but I normally would not use the term polymorphism there.

  • @Shad0wBenny
    @Shad0wBenny Před 2 lety +3

    Hi Saldina! Just a quick observation;
    In your title for Video 5, polymorphism is misspelled. Your "editor" (wink) snuck in the letter "a."
    Wow, today is the one year anniversary of when the course was posted,
    meaning, that misspelling has been up there the entire time.
    Now now Saldina, that's. just. criminal. :-) lol!

  • @ashrsfsiliman452
    @ashrsfsiliman452 Před 3 lety +2

    Thank you for your great job

  • @tharushinehara4318
    @tharushinehara4318 Před 2 lety

    helped me a lot!

  • @ermiasayele7111
    @ermiasayele7111 Před rokem

    thank you very much I learn much much in a few minuet

  • @nuamaaniqbal6373
    @nuamaaniqbal6373 Před 2 lety

    Thank You!

  • @ahmadghamsari8603
    @ahmadghamsari8603 Před 3 lety +1

    I am so glad to see your page accidentally! You are a very good teacher.
    Do you have any idea about using C++ on visual studio for programming micro controllers such as those are ARM based?

    • @connelly6375
      @connelly6375 Před 3 lety

      It is possible to program for MCU's in visual studio but it can be hard to setup, but it is possible. You can use STM32CubeIDE to develop C++ for ST MCU's, or Atmel Studio for Atmel MCU's, Atmel Studio looks almost identical to visual studio while STM32CubeIDE is based on eclipse.

  • @giovannimagni3493
    @giovannimagni3493 Před 3 lety +9

    Great Saldina !! Thx you so much for your effort.
    Just a little question about your example. To be honest, I'm not understanding rightly the reason of the pointer used there.
    I mean that same result could be get using derived class method directly. The derived classes are already instanced and yt1->CheckAnalytics() = cookingYtChannel.CheckAnalytics().
    Am I wrong ? What's the rule ?

    • @dynamic_dharsan3_1xor19
      @dynamic_dharsan3_1xor19 Před 3 lety +2

      I have the same doubt? Contact me if u got correct answer intimate me on discord @iAmDharsan#6700.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      I'm confused as well. Although this video is a good tutorial, I don't think she explained why we have to use pointers. If I were to guess, it might be to call the subclass methods from the superclass. That way, you don't have to type in different names from the subclasses. I might be incorrect but I think you would get the same results either way. However, I feel like it doesn't add up for the example she used because I don't see how using pointers would be more convenient than without them.

    • @jimena6194
      @jimena6194 Před 2 lety +1

      while that is correct a better example is at the end of her video on virtual functions.

  • @tejasdhule249
    @tejasdhule249 Před 2 lety +2

    This is my bad luck that I have visited this channel so late .... If I had visited this OOPs series an year before then definitely today I will be working with India's one of best Service Based Wipro Software Company 😓...... Because last year I got a chance for interview in Wipro Software LTD. And the interviewer asked me to implement these OOPs concepts with C++ code examples ..... But I was unable to do so because my concepts were not clear 😭..... Saldina Why don't you meet me an year before 😭

  • @christygeorge9938
    @christygeorge9938 Před 2 lety +1

    Hi Saldina,
    Your videos are really helpful,
    In this video ,inside the constructor, you haven't initialized the list type, shouldn't we ideally initialize all the variables, in constructor?
    Or else it might give run time issues in our program right

  • @juanmanueldeayanz1821
    @juanmanueldeayanz1821 Před 3 lety

    Gracias Saldina!
    ¿Harás vídeos sobre Software Architecture and Design Patterns más adelante?
    Saludos desde España.

  • @leonardopantoja7121
    @leonardopantoja7121 Před měsícem +1

    Son Interesantes tus videos.

  • @charleswahome7936
    @charleswahome7936 Před měsícem

    Great video. If I may ask, there is this concept that method overriding must happen for us to implement polymorphism. And a virtual function must be declared in the base class so that the overriding can be done in the child classes. Is it a must we do overriding of methods in the child classes? Or must we create the virtual function in the baseclass to make it abstract?

  • @starthustling3290
    @starthustling3290 Před 3 lety +1

    Thanks

  • @madhusankawijerathne8435

    Than you!

  • @abdallahshihab3106
    @abdallahshihab3106 Před 3 lety

    please keep making videos .

  • @isrza
    @isrza Před 2 lety

    Using pointer is exactly what I was looking for. As a student with java experience I stuck about using different type of objects derived from a base class in a single function. Using parameter as a pointer of base class in function is what I needed, thank you so much.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      Do you know why she uses pointers in this video? I ask because I don't think she explained why.

    • @isrza
      @isrza Před 2 lety +1

      @@joegongamer8637 She shows how the polymorphism works in C++. Imagine you have a program where it does the exact same function for for all objects but the implementation of these functions is different. In this case you would have create a separate function for each object, but with polymorphism you can use parent class as a type ( pointer form for c++) and then use it for all derived classes.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety +1

      @@isrza I think I somewhat get what you mean. She did make a good C++ video on polymorphism. However, I still don't think she explains clearly why we would use pointers in this video. So, if she doesn't want to give a better understanding of why use pointers for polymorphism, then can you please provide me a clearer explanation?

    • @isrza
      @isrza Před 2 lety

      @@joegongamer8637 well let me give you an explanation about in practice. Imagine we have a a game where you can shoot enemies friends and object ( boxes and etc.). But I you might have guessed each object will give you a different reaction ( enemy will lost health, box will collapse, fried will also lost health but tell you be careful). In this case all these objects have a property call getHit, but have different implementation. But in order to get this property work our bullet objet have to call this property whenever it meet with an object which has a properly getHit. But we don't want to have a long if else statements. Instead we want to use an argument which can represent all hitable objects. Bu beaucoup of the syntax kr nature of C++ we cannot give a parent call as arguments and pass ther child class in use. In order use use polymorphism we have to pass that argument as a pointer, this is something about nature of c++.
      czcams.com/video/MZOrGXk4XFI/video.html . This the reference of my explanation. You can take a look if you want. It is c# but focus on the concept than language. As you can see in c# we don't use pointers, neither in java. So usage of pointers is only about syntax of C++.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      @@isrza Although I appreciate your efforts in your explanation, I unfortunately still somewhat get what you mean. What I can understand is how it can make you write less code when you have a lot of objects, loops, and if/else statements to deal with. If using pointers is the only way for the superclass to access the same method from the subclass(ex. Animal tries to call speak() to print out the respected animal sound depending on the type of subclass animal), then I can understand. There are some cases where using pointers is just a personal choice. Her example @13:48 would print the same results even without pointers, just a different way of coding it. The same goes for the GetInfo method because you can also do Animal test = daDog; test.GetInfo(); to get the information about daDog object. If you're dealing with let's say multiple Animal objects, you can create an Animal array. The only things I can understand using pointers when it comes to polymorphism are if it's the *only way* for the parent object to access the same method from its child object OR for the parent object to pass the child object by reference, which would allow the programmer to get and modify its original properties. Other than that, I don't see why else one should use pointers for polymorphism.
      Thank you for posting the link, I'll see if I can check it out as I'm also interested in C#, game dev, and gaming.

  • @roros2512
    @roros2512 Před 3 lety +3

    why do you use pointers to get analyitics? shouln't be the same to use a method? thanks Saldina

  • @ruchitechster
    @ruchitechster Před rokem +1

    Hey Saldina i'm from India, in my 2nd year of BCA i have C++ but i can't understand anything. Your videos are very easy to understand and so helpful, Thanks a lot :)

    • @kilipkumar
      @kilipkumar Před 9 měsíci

      you are right , I am also doing BCA course in Gujarat . i cant speak english rather than can understand all the consepts that saldina explained .

  • @JarekAtWork
    @JarekAtWork Před rokem

    Without you, I wouldn't be here.

  • @crazycoder9356
    @crazycoder9356 Před rokem

    thanks.

  • @anonymousbelgique7331
    @anonymousbelgique7331 Před 2 lety

    thank you vm

  • @xiaonanfan6543
    @xiaonanfan6543 Před rokem

    pls can you make some middle sized C++ Project that we can use and practice the C++ knowleadge we leaned from you,thanks.

  • @indiangigachad777
    @indiangigachad777 Před 3 lety

    Hey Saldina, I am going through the book C++ Primer Plus 6th Ed....im stuck on chapter 12-13 dynamic memory alloc, and inheritance...how would you push through in times when you get stuck on a concept?

  • @Itsme1n1ly
    @Itsme1n1ly Před 2 lety +1

    Queen of C++

  • @smpbih
    @smpbih Před 3 lety +2

    prelijepa si

  • @erende44
    @erende44 Před 2 lety

    maybe not so important but you have a typo in the title of this video :) Thank you for your work!

  • @muhammadaon9147
    @muhammadaon9147 Před rokem

    std::cout

  • @yashsonawane905
    @yashsonawane905 Před 2 lety +2

    What is the use of pointer here? I really didn't get it. Can you explain it, please?

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      I don't know if she explained it well enough but I think it's for the parent class to access the same method from the child class. You need the Practice method in the parent class cause that's how you can have your child classes get the same method but different implementation. It doesn't make sense if the subclass gets the Practice method while the superclass doesn't cause it's like where did the children get their traits from(they have to get it from their parents). Using her example, let's say you want to store a cooking YT channel(subclass) in a YT channel(superclass). If you try to call the Practice method on this superclass, it won't call the practice method from the cooking channel subclass. Instead, it would call the practice method from the YT channel superclass. This provides an inaccuracy(logical error). The way to fix this is to have the parent object be a pointer object *AND* having the parent method has the code word: virtual(I have yet to figure out why that is). This would let the parent object point to the practice method in the cooking channel subclass, thus, being able to print what a YT cook should practice(instead of what a default CZcamsr should practice).
      Another reason is to pass by reference. If you want to access the original object and modify its properties, then pointers are a must. Hopefully, this explanation helps(idk whether you already found your answer or not).

  • @meisam7144
    @meisam7144 Před rokem

    Why did you define pointers to access CheckAnalytics? Couldn't you access them through the already defined objects? Great videos btw...

  • @grosucristi6599
    @grosucristi6599 Před rokem

    At 13:20 why did you use pointers to call a method from base class if you can do it directly from derived class?

  • @TheDarkLordSpaniard
    @TheDarkLordSpaniard Před 3 lety +6

    Hello! Why do we use pointers instead of for example singersYtChannel.CheckAnalytics(); since it's public already. I might've missed something.
    Cheers for the course!

    • @KishoreG2396
      @KishoreG2396 Před 3 lety

      The pointers are what polymorphism allows us to do: access the derived class through a pointer of the base class.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy Před 2 lety +2

      @@KishoreG2396 But why? It's much easier to just type in object name and then invoke the method directly.

    • @KishoreG2396
      @KishoreG2396 Před 2 lety +5

      @@GauravSingh-ku5xy Because in some cases we want to use more generic behavior.
      For example, let's say you have an Animal class, and all it's derived classes are types of animals like Dog, Cat, etc. If you have an Animal*, you can store any animal in it, so you don't need to worry about it specifically being a Dog, Cat, or something else. You can perform a generic action on an Animal, like Animal::eat() or Animal::walk() without knowing the derived class type.
      Also, you can store an array of multiple different Animal types if it is an array that stores Animal. Let's say you have an array that represents a zoo (Animal zooAnimals[5] ). You could store different types of animals, like 1 Zebra, 2 Giraffes, and 2 Lions. Whereas if the type of the array was just a specific object type, you could only store that single object type like Dog or Cat.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy Před 2 lety +2

      @@KishoreG2396 I got it man. That was a good explanation.

    • @GauravSingh-ku5xy
      @GauravSingh-ku5xy Před 2 lety +2

      @@KishoreG2396 Also, so here we are seeing polymorphism in an object (because same pointer can also point to a different object) and also in its function(The function has same name but different implementation). Right?

  • @teprox7690
    @teprox7690 Před rokem

    CheckAnalytics is public for both subclasses. Why you need the pointers?

  • @ronitakhariya4094
    @ronitakhariya4094 Před 3 lety +1

    why did we use pointers instead of just using
    cookingYtChannel.CheckAnalytics();
    ?
    why create a *yt1 for it?

    • @KishoreG2396
      @KishoreG2396 Před 3 lety +1

      That's what polymorphism is. The pointer was used because we want to access the derived class instance through a base class pointer.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      @Ronit Akhariya Maybe it's because passing by value won't give you the original results from the CheckAnalytics method. Pointers let you pass by reference which means you can access the original properties of the child object and modify it. Without pointers, you'll affect its copy instead of the original object. Hopefully, I'm correct about this cause I'm still waiting for K G. to confirm if this reasoning is correct.

    • @KishoreG2396
      @KishoreG2396 Před 2 lety +1

      @@joegongamer8637 Check the comments of the previous thread. I posted a reply

  • @Brusselsprouts2023
    @Brusselsprouts2023 Před 2 měsíci +1

    Saldina here!! to rescue again!!

  • @382946rthu
    @382946rthu Před 2 lety

    Probably wouldn't have been a bad idea to show what happens when the derived class is cast back to the base class or wait practice is missing from the base class. To be polymorphic shouldn't the base class also have had a practise method?

  • @fxsurgeon1
    @fxsurgeon1 Před 2 lety +1

    Hi, thanks for your great content. Could you explain why you used pointers to the base class instead of invoking the CheckAnalytics method directly from the objects?

    • @ddddd1687
      @ddddd1687 Před 2 lety

      Hi have you found any answer to your question? Because I am wondering the same thing 😂

    • @fxsurgeon1
      @fxsurgeon1 Před 2 lety

      @@ddddd1687 I moved to Python and feel much happier lol

    • @ddddd1687
      @ddddd1687 Před 2 lety

      Hahahah 🤣 OK thanks

    • @day4834
      @day4834 Před 2 lety

      Hi, I believe this was just for learning purposes, so that we know that a derived class can be called via a pointer in the bases class and a function can be invoked using such pointer.

    • @ddddd1687
      @ddddd1687 Před 2 lety

      @@day4834 Hi ,thank you for your answer :)

  • @pranavkotesh.v7556
    @pranavkotesh.v7556 Před 3 lety +2

    Im here from freecodecamp. And god your gorgous!

  • @Dani-mp2we
    @Dani-mp2we Před 3 lety +1

    I dont understood. Why do you deal with pointers in this video? Is that extra? Or are there in context with the polymorphismus?

    • @KishoreG2396
      @KishoreG2396 Před 3 lety +2

      The reason we use pointers is because we are trying to access the functionality through the base class. So we create a base class pointer, but we set it equal to the address of a derived class instance. Thus, the same pointer can be used to refer to any derived class instance. That's what polymorphism is.

  • @asadkhan-zg3rn
    @asadkhan-zg3rn Před 3 lety

    ma'am can you please make tutorials of JavaFX..!!

  • @rwagasanaelisa1379
    @rwagasanaelisa1379 Před 9 měsíci

    you speak understandable language
    but i request you to do mre examples for better understanding

  • @absamurai
    @absamurai Před 2 lety

    Hi! There is a typo in the video caption (polymorphisAm).

  • @siddharthasarmah9266
    @siddharthasarmah9266 Před 3 lety +1

    Can you please increase your video sound. Really like your tutorials

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      I can try 😊
      What do you think about the sound quality of this video czcams.com/video/42t2-6Tqy0U/video.html
      Is it any better? 🤔
      I tried to increase the sound a little bit in that video, but I didn't want to increase it too much, because then you can hear my air conditioner buzz in the background 😒

    • @siddharthasarmah9266
      @siddharthasarmah9266 Před 3 lety +1

      @@CodeBeauty yah the second one is much better😃😄

  • @debjyotinandi9140
    @debjyotinandi9140 Před 2 lety +1

    Amy reminds me of the owner of Amy's bakery from Kitchen Nightmares

  • @uguryucestudent281
    @uguryucestudent281 Před rokem

    What happened if we do not use polymorphisam?

  • @marathirada1199
    @marathirada1199 Před 2 lety

    Pls send code of this tutorial in description

  • @arjunans5139
    @arjunans5139 Před 5 měsíci

    If you have watched previous videos , click 2:57

  • @zihadFromPhero
    @zihadFromPhero Před 3 měsíci

    is that actually polymorphism ??
    the two function is independent on their own way. they are declared in the 2 independent derived class.
    in my knowledge polymorphism is a process to override the data. so that compiler can handle different function with same name and decide that what function should run.

  • @yashpatil9247
    @yashpatil9247 Před 3 lety

    why there is a need to initialize constructor of parent class in every inherited class

    • @joegongamer8637
      @joegongamer8637 Před 2 lety +1

      If I understand what you're trying to ask, it's required for the subclass' constructor to be initialized from the superclass. It's kinda like without the child having inherited traits from the parents, the child wouldn't exist.

  • @kikosmiletv4531
    @kikosmiletv4531 Před rokem

    new subscriber here, how can you be so intelligent and very pretty at the same time?

  • @noorallahpayanda
    @noorallahpayanda Před 3 lety +1

    why do you not have a video for the structure in c++

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      Hahaha, I just didn't find time to create it so far. Thanks for showing interest 🤗

    • @noorallahpayanda
      @noorallahpayanda Před 3 lety

      @@CodeBeauty thank you from your response

  • @konstantine3466
    @konstantine3466 Před 3 lety

    Polymorphism... As say in our Odessa: explain kroz dupe. Oh, women. Saldina, you're so bloody irresistible!

  • @JarekAtWork
    @JarekAtWork Před rokem +1

    Sometimes I think you're not real. No computer scientist changes their clothes so often.

    • @CodeBeauty
      @CodeBeauty  Před rokem

      Hahaha, very much real and fancy 😅🥰

  • @nezokochaan3198
    @nezokochaan3198 Před 3 měsíci

    6:58 😳😳😳😳

  • @fusiontv5269
    @fusiontv5269 Před 3 lety

    11:18

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      Yeah, I think using pointers for polymorphism should be a burning question for her OOP in C++ video.

  • @amaanmajeed4068
    @amaanmajeed4068 Před 3 lety +1

    John Sings

  • @SILX
    @SILX Před 2 lety +1

    btw, you spelt polymorphism wrong in the title

  • @ahasanhabibsajeeb1979
    @ahasanhabibsajeeb1979 Před 3 lety

    Your pronunciation " PublishedVideoTitles" is aesthetic 😅

  • @GenjaOrigins
    @GenjaOrigins Před 2 lety

    cpp overriding vs overloading thats annoying. I thought i knew but clearly i messed things up.
    There is something i that connects that but its different damn.
    Polymorphism is...
    -CompileTime "Static Polymorphism" e.g method overloading
    -RunTime "Dynamic Polymorphism" e.g function Overiding
    But Overloading is either
    -Operator Overloading _Operator overloading is a compile-time polymorphism in which a standard operator is overloaded to provide a user-defined definition to it.
    -Function Overloading _Function overloading is also a type of compile-time polymorphism which can define a family of functions with the same name. The function would perform different operations based on the argument list in the function call. The function to be invoked depends on the number of arguments and the type of the arguments in the argument list.

    • @GenjaOrigins
      @GenjaOrigins Před 2 lety

      Method is a bit different from function but we need to say its the same thing. This example that you are using i think its function overriding so its not polymorphim but a type of polymorphism. I think thats what i need understand cause its complicated xd. So i guess polymorphism is just an idea an ability of an object to have many forms maybe and it has different types.

  • @tahmid1847
    @tahmid1847 Před rokem

    Ilhan are you here?

  • @user-td4pf6rr2t
    @user-td4pf6rr2t Před měsícem

    Academia is Hard.

  • @shoshanamofaz3012
    @shoshanamofaz3012 Před 3 lety

    Polymorphic code like hackers use? It’s hard to detect. Great for creating a back door in the network. Bad stuff

  • @mercynik2019
    @mercynik2019 Před rokem

    why you made everything so complicated like its hard to understand for a beginner in oops like me ..

    • @CodeBeauty
      @CodeBeauty  Před rokem +1

      There are 4 videos prior to this one that you should watch. This is part 5. If you watch those video then this should be easy to understand 🤔💡

    • @mercynik2019
      @mercynik2019 Před rokem

      @@CodeBeauty ohh thanks i will check them for sure , operator overloading type of polymorphism is too difficult for me
      & I'm searching for it and just find your video...... Thanks for your reply ☺️ hope this will helps me to find 😊

    • @CodeBeauty
      @CodeBeauty  Před rokem +1

      @@mercynik2019 check out object-oriented programming playlist on my channel, n watch it from beginning, it goes step by step-by-step 😃

    • @mercynik2019
      @mercynik2019 Před rokem

      @@CodeBeauty Got it, thanks ☺️

  • @kotinakarwak7857
    @kotinakarwak7857 Před 3 lety +1

    Please pad the comment for me to understand what that line of code is doing.
    CZcamsChannel *yt1 = &cook01; //assign a pointer to a base class enitiy to an instance of its derived object address.

    • @tombarrett2306
      @tombarrett2306 Před 3 lety +1

      This line of code creates a pointer for the Type CZcamsChannel then it sets it equal to the address of cook01 via the use of the & (Address operator)

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      @@tombarrett2306 The next question I have is if it gives the same result as without using pointers?

    • @tombarrett2306
      @tombarrett2306 Před 2 lety +1

      @@joegongamer8637 So in response to your question if I understand what you're asking. Pointers are used for referencing things so you can point a pointer at a location in memory and access it. However a pointer is only a reference what it points to determines what will happen when it is dereferenced. The reason to use pointers is it gives you better control of memory.

    • @joegongamer8637
      @joegongamer8637 Před 2 lety

      @@tombarrett2306 Thanks for trying to understand and explain more about pointers. Pointers are a hard lesson to learn as it took a long while for me to understand them well. I plan on relearning them in my spare time.
      *What I meant to ask was if she didn't use pointers, would the result still be the same at **13:48**?*

  • @RakyFX
    @RakyFX Před 3 lety +1

    Ohh how beautiful girl

  • @jurekpacewicz2693
    @jurekpacewicz2693 Před 2 lety +2

    Hi Saldina, I enjoy your lectures. I have got some suggestions for you to master your presentation. The fundamental thing is that you use (unfortunately as many others) the default font size, which is definitely too small. It has to be at least 2 points more, if possible even 3 points. Not everyone has got falcon's eyes. The most important thing is a screen organisation. You put an enormous big banner with your IT addresses. That takes a lot of screen space. That info banner should not be even there or much, much smaller. I enjoy seeing you "Pretty Woman" with your beautiful long hair. Unfortunately it doesn't help to concentrate on lectures, in contrary it distracts an attention a lot. Again it is much, much too big! Try to see your lectures on different screens, from smartphones through notebooks ending on big 30" - 50" screens. The knowledge you give should be given in the easiest and the most readable way. The black screen is the worst readable solution!!!
    I wish you would be the best.
    Zdrowia Radosci i samych PRZYJEMNOSCI from Poland. Jurek, your fun

  • @ivans7
    @ivans7 Před rokem

    you complicated the thing. I still don't understand.. :(

  • @madelinelopez2035
    @madelinelopez2035 Před rokem

    Hi Saldina - Love your content! 🙂Quick question: what is the benefit to using the "pointer to derived class method" approach over just directly calling the "derivedClass.method()"? In your last example, my first instinct was to use singersYtChannel.CheckAnalytics(). Why use the pointer instead?

    • @saiganeshmanda4904
      @saiganeshmanda4904 Před rokem

      I am not an expert but the way I see it, the second method she explained instantiates two objects (of each derived class) from the same superclass (or parent class) rather than invoking the CheckAnalytics() function for two objects defined from each derived class separately.
      So, instead of instatiating objects from child classes separately, the second method did it from instantiation from the one single parent class itself.
      The reason I wondered the same question as you did is because I thought -
      This second way of implementing polymorphism using pointers would also require you to create two separate objects. How is it any better than the first implementation (the one without using pointers)?

  • @michaelvaland5467
    @michaelvaland5467 Před rokem +2

    hey so why can't we just call the check analytics method without having to create a pointer of the base class and calling it directly on the derived class like: cookingYtChannel.checkAnalytics();

  • @azizprimbetov2745
    @azizprimbetov2745 Před rokem

    Hello Saldina i have a question why do i need to use pointer checkanalytics method is public we can check it directly using object ytb.checkqualiyt() method

  • @lifehealerzr2508
    @lifehealerzr2508 Před 11 měsíci

    singers youtube channel does not work.