OOP Basics II Flashcards
What is a constructor?
A method named __construct(), which is called on each newly-created object.
If the child class defines a constructor, the parent constructor is…
…not called.
How do you run a parent constructor?
Call parent::__construct() within the child constructor.
When is a destructor called?
As soon as there are no other references to a particular object.
How do you call a parent destructor?
Call parent::__destruct() in the destructor body.
Is a destructor called if script execution is stopped using exit()?
Yes.
If a method is declared without an explicit visibility keyword, what is its visibility?
Public.
Can objects of the same type access each other’s private and protected members, even though they are not the same instances?
Yes.
What is the scope resolution operator?
::
Allows access to static, constant, and overridden properties or methods of a class.
What does the ‘static’ keyword do?
Declaring class properties or methods as ‘static’ makes them accessible without needing an instantiation of the class.
Can a property declared as static be accessed with an instantiated class object?
No.
Can a static method be accessed with an instantiated class object?
Yes.
Can classes defined as ‘abstract’ be instantiated?
No.
Any class that contains at least one abstract method must also be…
…abstract.
When inheriting from an abstract class, all methods marked abstract in the parent class must be…
…defined by the child.