Please get your code to a compilable form - everyone trying to read this has to guess what you actually mean several times to get that right. Regards, ab
angrybobcat
Posts
-
Something is wrong with the print command. -
Using the Observer and Observable ClassWhere "Observer" is actually "Observable" as you got it right in your first post, since "Observer" and "Subscriber" are basically the same thing.
-
problem with inheritanceTo explain that, take a look at what is executed and why. First of all, you create a new Derived-Instance as an instance of Base. Take a look at how you call the static method foo(): You dont access it in a static way (to use exact the phrase the compiler will warn you with) - which would be Base.foo() or Derived.foo() - but you call it on an instance. As mentioned, bObj is an instance of Base (because you declared it as that) and thus the static Method Base.foo() is called, which prints the "In Base.foo()"-Part of your output. If you declared it as an instance of Derived, the static method Derived.foo() would have been called there. To explain the part "In Derived.bar()" take a look at what is called next: In Base.bar() you call bObj.bar(); bObj was instantiated with new Derived(), so the method bar() on that object is overriden with the implementation in Derived, which prints then "In Derived.bar()". I hope that explains inheritance a bit better. ab