Static Binding and Dynamic Binding

后端 未结 6 1508
灰色年华
灰色年华 2020-11-27 13:46

I am really confused about dynamic binding and static binding. I have read that determining the type of an object at compile time is called static binding and determining it

6条回答
  •  青春惊慌失措
    2020-11-27 14:17

    For non-static functions, you use static binding whenever the function is non-virtual, i.e. the final keyword is applied to it and/or the function is private. final implies the function cannot be changed and the private keyword implies it only has class scope. Otherwise, dynamic binding is used.

    For static functions, static binding is always used. If a type A is passed in, it will run A's method, regardless of where A references.

提交回复
热议问题