2
Reply

what is the difference between override and new keyword?

giriraj katheeria

giriraj katheeria

18y
10.4k
0
Reply

    If we talk about inheritence than new keyword has a totally different meaning. suppose there is fuction in base class (virtual / non virtual) and we declare a new function in derived class with the same name but do not override it. then the compiler wd generate a warning stating tht this function is already defined in the base class. if we use new keyword thn the WE TELL THE COMPILER THT I AM AN EXPERIENCED PROGRAMMER AND I KNOW WHAT I AM DOING so plz dont generate a warning. virtual is the firat implementation of a function. override is another implementation of parent class function. new does not have ne effect except to stop the warning sealed is the last implementation of a funcyion

    Override V/S New

    Override is basically used for Function

    When we provide different definition to Base class function in derived class go for Override

    And

    New keyword is used to allocate memory to variable