Thank you so much for the detailed answer. Yep, I am studying C#. And the study guide sucks! You guys have been terrific with clarifying questions.
Here comes my next question which I noticed in the next chapter in the guide. Is it possible to pass arguments to a class declaration? Do you have any examples? Thanks in advance.
: : Whats the difference between static and dynamic binding? I fail to understand. Could someone please explain with an example? Thanks.
: :
: :
:
: It can all be boiled down to when the actions that take place during execution are known.
:
: Example 1:
: public class MyClass
: {
: public void DoSomething(){...}
: }
:
: public class MyOtherClass
: {
: public MyOtherClass()
: {
: MyClass mc = new MyClass();
: mc.DoSomething();
: }
: }The call to DoSomething was bound statically to the instance of MyClass that we had created on the previous line. This is known at compile time, and therefore is the only thing that can happen when this code runs.
:
: Example 2:
: public abstract class WidgetBase
: {
: public abstract void DoSomething();
: }
:
: public class ShinyWidget : WidgetBase
: {
: public override void DoSomething()
: {
: // implementation
: }
: }
:
: public class DullWidget : WidgetBase
: {
: public override void DoSomething()
: {
: // implementation
: }
: }
:
: public class MyOtherClass
: {
: public void DoSomethingWithAWidget(WidgetBase widget)
: {
: widget.DoSomething();
: }
: }When someone instantiates MyOtherClass, they will call DoSomethingWithAWidget and pass in an instance of ShinyWidget or DullWidget. We have no idea which one is going to be passed in, so we can't know at compile time which implementation of DoSomething is going to be called. This is dynamic binding.
:
: The concept of static/dynamic binding is certainly not only applicable to abstract classes. This is only one example. The same concept applies to virtual methods, in many cases.
: MyNonAbstractBaseClass bc = new ImInheritedFromMNABC();
: bc.VirtalMethodName();
This would use dynamic binding as well.
:
:
:
: P.S. I am looking forward to the next question in your study guide. Ever think about posting the entire list to save time?
: