High Level PHP Oop Concept

  • Abstract class’s abstract function cannot be declared private. It can be protected or public (default).
  • Abstract class’s non abstract method can be private.
  • To declare abstract keyword is abstract.
  • Any class’s public method can also be called like this Car::carSpeed(); , if there is no __construct declared or it is there but don’t need any arguments to initiate the class.
  • Narrowing is not allowed only widening is allowed in inheritance concept weather you are working with abstract class interface or just simple inheritance.(Narrowing:-decreasing access level like in parent it was public and in child you are changing it to the protected or private. Widening: – increasing the access level like in parent it is private and you are changing it to public or protected.)
  • Static method cannot be private it can be protected or public.
  • Interface can have static method but in that case it also should be declared static in implementing class.
  • Every method of interface must be public there is no other option.
  • Interface cannot contain any member variables, not even static, only functions are allowed.
  • Abstract class can contain any type of member variables (private, public, protected or static ).
  • When writing public static then keyword order doesn’t matter , you can write like this also static public.
  • When writing static method private or protected it will not give any error it can be. But the condition is you are using it in child class .if you will use it like this Car::carSpeed(); then it will show error.

Subscribe / Share

Article by Irfan Raza

Authors bio is coming up shortly.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>