php - Class inheritance - Calling properties and/or methods not in the parent class -


i'm trying understand class inheritance.

suppose have following code (php):

class {      public function fire() {         echo "fire!";      }  }  class b extends {      public function water() {         echo "water!";      } }  class c extends b {      public function lightning() {          echo "lightning!";      } }  $cobject = new c();  $cobject->fire();   

my questions are

  • even though fire() method not defined in class c nor class b, $cobject->fire() works. class c inherit not class b's methods, class a's methods? i'm trying find out how many levels deep inheritance go.
  • is there term calling property or method not exist in current object instance, property or method exists in parent or ancestor class? edit: in other words, fire() not defined in class c, $cobject can still call fire(). there particular term/jargon concept? (or part of definition of "class inheritance")

1) class 'b' 'a'. class 'c' 'b', therefor, 'c' 'a'. 'b' has rights , privileges in 'a', 'c' has well. c++ has concept of private inheritance gets little funky here, that's general idea. said in other answer, inheritance go far chain defined.

2) think meant ask "what function called not defined in derived class, instead in base class. type of function called virtual function. understand, every class function in php virtual function , can overridden (reimplemented in derived class) unless declared final.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -