Java Polymorphism: Compile time vs. Run time. Method Overloading vs. Overriding #17

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ค. 2017
  • Access 7000+ courses for 15 days FREE: pluralsight.pxf.io/c/1291657/...
    Java Tutorial for Polymorphism. There are its two types Compile time Polymorphism and Run time polymorphism. Method Overloading is Compile time polymorphism and method overriding is run time polymorphism.
    Source code files: bit.ly/2MC04SR
    Next Video : • Java abstract class - ...
    Previous Video : • Java OVERLOADING vs OV... .
    .
    Please donate and support my work
    (If you think my free tutorials are better than paid ones :)
    - Patreon: bit.ly/patreon-donate
    - Paypal/Payoneer: sriyank123@gmail.com
    - UPI (only for India): smartherd@okaxis
    :: If you want to develop a website or a mobile app, email me your requirement at sriyank.siddhartha@gmail.com :: Free demos provided beforehand ::
    - Access my premium courses: bit.ly/sriyank-courses
    Free Programming courses:
    - Ruby Programming: bit.ly/smyt-r
    - Dart Programming: bit.ly/smyt-d
    - Kotlin Programming: bit.ly/smyt-k
    - Java Programming: bit.ly/smyt-j
    - Kotlin Coroutines: bit.ly/smyt-coru
    Free Flutter course:
    - Flutter App Development: bit.ly/2Rg7EFR
    Free Android courses:
    - Android using Kotlin: bit.ly/smyt-ka
    - Android using Java: bit.ly/smyt-ja
    - Android Material Design: bit.ly/2SMJqU6
    - Android Jetpack Architecture: bit.ly/yt-j
    - Android Multiple Screen Support: bit.ly/smyt-mss
    - Android Retrofit: bit.ly/2Ee6GHn
    More free programming courses:
    - bit.ly/smy-list
    Check out my website:
    - bit.ly/smartherd
    Let's get in touch! [Sriyank Siddhartha]
    LinkedIn: bit.ly/sriyank-linkedin
    Facebook: bit.ly/smartherd-facebook
    Instagram: bit.ly/sriyank-instagram
    Twitter: bit.ly/sriyank-twitter
    Github: bit.ly/smartherd-github
    --- Thank you for your love and support ---

ความคิดเห็น • 112

  • @BoxerDogs
    @BoxerDogs 6 ปีที่แล้ว +12

    Instead of doing Animal animal2 = new Dog(); why wouldn't you use:
    Dog animal2 = new Dog(); since animal2 is of the type Dog?

    • @smartherd
      @smartherd  6 ปีที่แล้ว +11

      Everything in the video is done for some purpose. Animal animal = new Dog() shows that u can assign the sub class object of Dog to the super class reference of Animal but vice versa is not possible.

    • @BoxerDogs
      @BoxerDogs 6 ปีที่แล้ว +2

      I understand that you can assign the sub class object of Dog to the super class reference of Animal but vice versa. Here is what I don't understand. You can also do:
      Dog animal2 = new Dog(); animal2.eat();and still get "Dog Eating" as the result. So if create a dog object as type Animal (superclass) or as type Dog (subclass) either way the end result is still "Dog Eating."
      So if the result is the same whether a new dog object is of type Animal or type Dog, what is the advantage of defining a new dog object as type Animal? Why might somebody do this?

    • @smartherd
      @smartherd  6 ปีที่แล้ว +11

      It is the question of runtime. In the runtime if you are not sure what will be your object type then you should go for this approach. For example we often pass ArrayList object to a function which has super interface reference of List. If it still doesn't make things clear then here is a complete basic article on it, www.geeksforgeeks.org/referencing-subclass-objects-subclass-vs-superclass-reference/ . Hope it helps :)

    • @nightmarionetteprimordial3580
      @nightmarionetteprimordial3580 4 ปีที่แล้ว

      I hoped you finished this play list my dude! I guess he must have been planing to explain it or you had an influence on his other videos regardless he did state it takes time to make videos. Nevertheless, it took me along time to get here I hope you didn’t watch these straight through. Hahah I found out it’s good to download code and look at it to study what there doing with it from git hub. And seen this a lot! I knew it was going to be important.
      He is right, everything was done for a reason!

    • @TheDivineChords
      @TheDivineChords 4 ปีที่แล้ว +2

      I do have the same question and I am not convinced with the response yet

  • @sangeetakumar3857
    @sangeetakumar3857 6 ปีที่แล้ว +3

    Finally !! My main Java concepts are clear after watching your simple and high quality videos/presentation. I feel more confident now to face any upcoming interviews. Thanks a lot !

  • @tahajunaid9834
    @tahajunaid9834 5 ปีที่แล้ว +4

    your videos are so well explained thank you. i especially like how you summarize the videos

  • @felixgerschner
    @felixgerschner 6 ปีที่แล้ว

    Insane quality. Thank you for these videos.

  • @poojapalwai6064
    @poojapalwai6064 4 ปีที่แล้ว

    The contents of your videos is very well organized and explained , thank you for the video...

  • @technophile7024
    @technophile7024 5 ปีที่แล้ว +4

    Awesome tutorial, very clear to understand, top notch! Thanks for posting such a great video.

  • @guruprasadr7886
    @guruprasadr7886 5 ปีที่แล้ว

    Thanks a lot Sriyank Siddhartha sir, i strengthened my java knowledge and learnt some additional concepts in java through your videos

  • @user-ku2wo5ei8r
    @user-ku2wo5ei8r 4 ปีที่แล้ว +1

    You were awesome I made me strong understanding the pleomorphism

  • @SmartProgramming
    @SmartProgramming 5 ปีที่แล้ว +2

    really great, keep it up, thank you 👍👍👍👍🙂🙂🙂🙂

  • @shwetatripathi9093
    @shwetatripathi9093 5 ปีที่แล้ว +1

    Simply Amazing explanation! Thanks a lot.

  • @jasonsmith-iw4gm
    @jasonsmith-iw4gm 3 ปีที่แล้ว

    I am a seasoned Java programmer. But to teach my high school kid, I came across this video about polymorphism. By far, this is the BEST VIDEO for explanation on POLYMORPHISM. GOD bless you for putting together such a great video.

  • @coderbravo1275
    @coderbravo1275 2 ปีที่แล้ว +1

    Perfectly explained.
    Thank you Sir :)

  • @Tikorungbaka
    @Tikorungbaka 4 ปีที่แล้ว +7

    When overloading, you must change either the type or the number of parameters for a method.
    Method overloading is done to allow us to use the same methods names for multiple methods. The purpose behind this is that, you might have different functionality implementation for the same feature based on the difference in parameters and in that scenario you definitely want the same method names to be able to relate all of them with the feature.

    Overriding means that a method inherited from a parent class will be changed. But, when overriding a method everything remains exactly the same except the method implementation. What the method does is changed to fit in with the needs of the child class. But, the method name, the number and types of parameters, and the return type will all remain the same.

  • @himanshusinghnegi3639
    @himanshusinghnegi3639 2 ปีที่แล้ว

    your videos are awesome !!!! i have learned many new concepts through this playlist .... so thanks for providing us such great content !!!

    • @smartherd
      @smartherd  2 ปีที่แล้ว +2

      I love teaching. U love learning. Deal!

  • @gs-rc3eq
    @gs-rc3eq 3 ปีที่แล้ว

    that is ine good explanation on run time polymorphism and upcasting with super class....thank you!!! this cleared a big confusion for me....

  • @spenceremmanuel7563
    @spenceremmanuel7563 4 ปีที่แล้ว

    Thanks for posting such a great video!

  • @malumalu5594
    @malumalu5594 4 ปีที่แล้ว

    thanks bro. I can understand easily by like your way of teaching.tqq

  • @equinox6833
    @equinox6833 ปีที่แล้ว

    I have presentation tomorrow and u made it crystal clear .Very informative video thank you . Btw your voice is really nice

  • @rohitr6722
    @rohitr6722 4 หลายเดือนก่อน

    great video sir, love ur style of explanation

  • @reynaldosilva1115
    @reynaldosilva1115 2 ปีที่แล้ว

    Thank you for sharing your knowledge!

  • @mani76969
    @mani76969 5 ปีที่แล้ว

    Hi Mr.Siddhartha am watching your Java Tutorial all videos and I take notes also, you have Good teaching knowledge please put more more videos for based on programming. Thank you vary much

  • @zainwasem
    @zainwasem 2 ปีที่แล้ว

    Top notch very clear.

  • @shh1909
    @shh1909 6 ปีที่แล้ว

    Great videos great playlist

  • @potturikaruna4152
    @potturikaruna4152 5 ปีที่แล้ว

    nice sir each and every topic vedios we need

  • @gamingsports7250
    @gamingsports7250 6 ปีที่แล้ว

    Thank you for your java tutorials
    This videos clear my all java concept

    • @smartherd
      @smartherd  6 ปีที่แล้ว

      thank you very much 😉

  • @rahulmandal6139
    @rahulmandal6139 4 ปีที่แล้ว

    Great conceptual explanation 😊😊😊😊😊👨‍💻👨🏻‍💻

  • @evergreencreations6232
    @evergreencreations6232 ปีที่แล้ว

    Tq sir for your video.
    I got a clarity about this topic

  • @atulsoni9600
    @atulsoni9600 3 ปีที่แล้ว

    Great explanation

  • @jitendragorle
    @jitendragorle 7 ปีที่แล้ว

    Very nice and clear explanation, thanks siyank

    • @smartherd
      @smartherd  7 ปีที่แล้ว

      +jitendra Gorle thank you

  • @dhevanrajandran7632
    @dhevanrajandran7632 4 ปีที่แล้ว +1

    the best video:)

  • @BeeshoStudying
    @BeeshoStudying 2 ปีที่แล้ว

    thank you for the video

  • @sagarvarma3919
    @sagarvarma3919 4 ปีที่แล้ว

    It really helped 😊

  • @luckysuma1769
    @luckysuma1769 4 ปีที่แล้ว

    Excellent 👍

  • @shubhjeetrajput2505
    @shubhjeetrajput2505 4 หลายเดือนก่อน

    videos are informative and very clear, you can also tell the theoretical part for interview propectives

  • @Masarap1959
    @Masarap1959 5 ปีที่แล้ว +2

    Perfect! BUT could we need to extends keyboard when we used reference variable to other class object?

    • @Tikorungbaka
      @Tikorungbaka 4 ปีที่แล้ว

      we use extends keyword to define a child class so that it inherits from a parent class

  • @dhrock251
    @dhrock251 7 ปีที่แล้ว

    +Smartherd great work....5 videos in one day...

  • @ManzoorHussain-gz1vk
    @ManzoorHussain-gz1vk 5 ปีที่แล้ว

    thank you very much.

  • @rahulsoni-lx5rb
    @rahulsoni-lx5rb 3 ปีที่แล้ว

    awsm🙌

  • @SurajKumar-mq9ww
    @SurajKumar-mq9ww ปีที่แล้ว

    nice explanation brother

  • @sachidanandapallai6016
    @sachidanandapallai6016 ปีที่แล้ว

    thank you dear

  • @shubhamsutar7567
    @shubhamsutar7567 3 ปีที่แล้ว

    nicely explain

  • @vaibhav0809
    @vaibhav0809 2 ปีที่แล้ว

    great...very well explained by @Smartherd

  • @soniafaizabenchebana3128
    @soniafaizabenchebana3128 3 ปีที่แล้ว

    merci beaucoup

  • @enamulhaque5697
    @enamulhaque5697 6 ปีที่แล้ว

    nice Lecture bro....Plz upload a lecture about null pointer exception....

  • @shree4046
    @shree4046 6 ปีที่แล้ว

    Hello sir I have downloaded all.your Java tutorials..plz continue.i wanna learn

    • @smartherd
      @smartherd  6 ปีที่แล้ว

      sure. But just a request do not download. watch it online if possible. This is our living

  • @kanikasarkar7690
    @kanikasarkar7690 5 ปีที่แล้ว

    It is too good to understand

  • @tanishadixit_
    @tanishadixit_ 3 ปีที่แล้ว

    Can l use upcasting normally in java programs where l haven't declared method overriding??

  • @emanalikhan591
    @emanalikhan591 ปีที่แล้ว

    bahi tum kitna acha samjhaty hou yaar ...itna khabi mami papa ney nhi samjhaya acha ...bahi love you hou gya bahi

  • @tessythomas9910
    @tessythomas9910 4 ปีที่แล้ว

    Thanku

  • @redpersimmon6940
    @redpersimmon6940 ปีที่แล้ว

    Thankyou

  • @sintushukla6709
    @sintushukla6709 ปีที่แล้ว

    Guy's, After filtering many lecture's for Java. I found it the best one. Thankyou @smartherd

  • @chetanchavan1187
    @chetanchavan1187 5 ปีที่แล้ว

    thanks

  • @kamal-coder
    @kamal-coder ปีที่แล้ว

    nice sir understand

  • @abhinandkk4681
    @abhinandkk4681 5 หลายเดือนก่อน

    thankyou

  • @samudragupta719
    @samudragupta719 5 ปีที่แล้ว

    Good explanation Indeed !

  • @tnkwok9682
    @tnkwok9682 5 ปีที่แล้ว

    Thank you Sir for your effort in preparing the tutorial.
    However, I get different result when coding your upcasting example in the IDE. What I got from the following line of codes was "Animal Eating" instead of "Dog Eating":
    Animal animal2 = new Dog();
    animal2.eat(); //result: Animal Eating

  • @sadaffatima2076
    @sadaffatima2076 5 ปีที่แล้ว

    Great

  • @fazilatali7545
    @fazilatali7545 6 ปีที่แล้ว

    sir plz make a vedio about the concept of polymorphism using only abstract classes

  • @varshamehra8164
    @varshamehra8164 5 ปีที่แล้ว

    nice

  • @sagarsinghrajpoot6788
    @sagarsinghrajpoot6788 4 ปีที่แล้ว

    Nice ;)

  • @mathukumallipallavi8795
    @mathukumallipallavi8795 6 ปีที่แล้ว

    Excellent...

    • @smartherd
      @smartherd  6 ปีที่แล้ว

      thank you very much 😉

  • @tshepojaphta8718
    @tshepojaphta8718 6 ปีที่แล้ว

    thanks is clear

    • @smartherd
      @smartherd  6 ปีที่แล้ว

      Thanks alot. Make sure you visit www.smartherd.com/ . A lot of content will be there soon

  • @aravindsagarpa78
    @aravindsagarpa78 5 ปีที่แล้ว

    Very nice classes

  • @chintadakiranraj7893
    @chintadakiranraj7893 2 ปีที่แล้ว

    sir how can i get all the videos of java from ur channel and i have subscribed already

  • @sayanbera28
    @sayanbera28 ปีที่แล้ว

    is Runtime Polymorphism and Inheritance related?
    Does Runtime Polymorphism follow Inheritance concept?

  • @veerraghavareddy735
    @veerraghavareddy735 6 ปีที่แล้ว

    Please upload remaining videos by explaining remaining topics like interface,packages,applet and soon in Java because we are the follower of you

    • @smartherd
      @smartherd  6 ปีที่แล้ว

      +Veerraghava Reddy soon I will be up with my website.. Catch you there

    • @veerraghavareddy735
      @veerraghavareddy735 6 ปีที่แล้ว

      Your site is not opening

    • @somareddy3060
      @somareddy3060 6 ปีที่แล้ว

      Smartherd

    • @vibrantworld4531
      @vibrantworld4531 6 ปีที่แล้ว

      Please upload more videos sir..the advanced videos

  • @souravkarjole7587
    @souravkarjole7587 ปีที่แล้ว

    is below what i stated is correct ? Thank You🙇‍♂🙇‍♂
    Compile-time: The compiler checks if the methods you are trying to call exist in the reference type (interface or class) and whether they have the correct signatures.
    Runtime: The program runs, and when a method is called using an object, it checks the type of the actual object being referred to (which is determined at runtime). Then, it looks for the appropriate method in the actual object's class hierarchy and executes that method.

    • @subasubashni9014
      @subasubashni9014 10 หลายเดือนก่อน

      I think it's right! And this is what I was trying to comprehend. Thanks.

  • @vibrantworld4531
    @vibrantworld4531 6 ปีที่แล้ว

    Sir please upload more videos

  • @eunardayangco2987
    @eunardayangco2987 5 ปีที่แล้ว

    I have a class Name Database which has insert(),delete(),update() methods...I have another two class which is InventoryDatabase and UserDatabase. Both of them is inherit the Database..Now InventoryDatabase has its own methods which is getInventory as well as UserDatabase which is loginUser(). Now here is the problems. I call like this: Database db = new InventoryDatabase(); and got no error. But when I call the method like db.getInventory(); and error occurred that getInventory() is not found. I just learn Polymorphism but I don't know exactly why this error was happened. Please help me!

    • @indiras8833
      @indiras8833 5 ปีที่แล้ว

      Eventhough you have created an object for InventoryDatabase, your reference variable is of type Database. so you cant invoke subclass methods.
      Simply if you are having a reference of a super class for the object of a sub class, then you can only call the methods in the superclass with that reference.

  • @mrtayyabmughal7209
    @mrtayyabmughal7209 7 ปีที่แล้ว

    Plz upload next parts

  • @user-tf6nu3tg7r
    @user-tf6nu3tg7r ปีที่แล้ว

    woww

  • @consejosparasermejor4451
    @consejosparasermejor4451 4 ปีที่แล้ว

    A question: Is there any way to use method overriding and overloading at the same time?

    • @smartherd
      @smartherd  4 ปีที่แล้ว

      Yes u can do it. Y not

    • @khouloudbentaoues641
      @khouloudbentaoues641 4 ปีที่แล้ว

      @@smartherd oveloading requires to change the parameters or the return type of a method while in overriding the signature and the return type stay the same so how is that possible ?

  • @manjusha9630
    @manjusha9630 6 ปีที่แล้ว

    How can you then call eat method in animal class and print animal eating in main method
    You will simply create animal object then what is the use of extending

    • @manjusha9630
      @manjusha9630 6 ปีที่แล้ว

      You have well explained the reference and object but compile time run time u didn’t explain

  • @manzoorahmad3519
    @manzoorahmad3519 7 ปีที่แล้ว +1

    Please Upload more videos of java

    • @smartherd
      @smartherd  7 ปีที่แล้ว

      +Manzoor Ahmad it's the end bro... U can now go ahead with Java programming

  • @hemanthk2561
    @hemanthk2561 3 ปีที่แล้ว

    Plzz put video on multi-threading bro...

  • @FahimAhmed-iq7do
    @FahimAhmed-iq7do 4 ปีที่แล้ว

    class name Animal and method name is add. what the work of add method in animal class?

  • @BeFox
    @BeFox 4 ปีที่แล้ว

    Bhai please hindi mein padao kasam se jabardast videos hai aapke

  • @er.abhishek1108
    @er.abhishek1108 4 ปีที่แล้ว

    Well explained. There is one error. In rules of polymorphism, rule no. 3 you have to mention reference variable of child class should not point to parent class object. What you have written is confusing. You have only mentioned reference variable not reference variable of child class.

  • @manjusha9630
    @manjusha9630 6 ปีที่แล้ว

    After upcasting if is giving child class method what is the use of upcasting

  • @kumar17299
    @kumar17299 3 ปีที่แล้ว

    it's to listen. But if it is executable code, then that will more make sense.

    • @smartherd
      @smartherd  3 ปีที่แล้ว

      Watch next video for the demo and code mate

  • @theartist8835
    @theartist8835 5 ปีที่แล้ว

    The question here is what is it that you can do with this
    Animal animal2 = new Dog();
    that you can not do with this
    Dog animal2 = new Dog();

  • @barshabhattacharjee6788
    @barshabhattacharjee6788 3 ปีที่แล้ว

    For more : th-cam.com/video/q2RgFH1rPos/w-d-xo.html

  • @thilwai.4238
    @thilwai.4238 2 ปีที่แล้ว

    IT tutorial on utube is not the platform to show off your English communication skills...it would be more better if you had explained this lecture in Hindi...