OOP Basics II Flashcards

1
Q

What is a constructor?

A

A method named __construct(), which is called on each newly-created object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If the child class defines a constructor, the parent constructor is…

A

…not called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you run a parent constructor?

A

Call parent::__construct() within the child constructor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When is a destructor called?

A

As soon as there are no other references to a particular object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you call a parent destructor?

A

Call parent::__destruct() in the destructor body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is a destructor called if script execution is stopped using exit()?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If a method is declared without an explicit visibility keyword, what is its visibility?

A

Public.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can objects of the same type access each other’s private and protected members, even though they are not the same instances?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the scope resolution operator?

A

::

Allows access to static, constant, and overridden properties or methods of a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the ‘static’ keyword do?

A

Declaring class properties or methods as ‘static’ makes them accessible without needing an instantiation of the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can a property declared as static be accessed with an instantiated class object?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can a static method be accessed with an instantiated class object?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can classes defined as ‘abstract’ be instantiated?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Any class that contains at least one abstract method must also be…

A

…abstract.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When inheriting from an abstract class, all methods marked abstract in the parent class must be…

A

…defined by the child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of visibility do methods inherited from an abstract class need to have?

A

The same or a less restricted visibility.

17
Q

Does a method that inherits from an abstract class have to have the same number of arguments?

A

Yes.

18
Q

What is an object interface?

A

Interfaces specify which methods a class must implement, without having to define these methods.

19
Q

What is the required visibility for methods declared in an interface?

A

Public.

20
Q

How do you implement an interface?

A

With the ‘implements’ keyword.

21
Q

How do you implement more than one interface?

A

By separating each interface name with a comma.

22
Q

A class implementing an interface must use the exact same ____ ____ as are defined in the interface.

A

Method signatures.

23
Q

How are interface constants different from class constants?

A

Interface constants cannot be overridden by a class/interface that inherits them.