OOP Basics III Flashcards

1
Q

Which overrides? The methods of a trait, or similarly-named inherited methods of a parent class?

A

Methods of a trait.

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

Which overrides? The methods of a class, or similarly-named methods of a trait?

A

Methods of a class.

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

What is the ‘insteadof’ keyword?

A

‘Insteadof’ is used to specify which trait’s methods should be used in a name conflict.

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

What is the ‘as’ keyword?

A

‘as’ is used to assign alias names to conflicting trait methods.

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

Can traits access private properties or methods of composing classes?

A

Yes.

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

Can composing classes access the private methods and properties of traits?

A

Yes.

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

Traits are essentially language-assisted __ _ __.

A

copy and paste

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

Can traits include abstract methods?

A

Yes.

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

Traits are a mechanism for __ __ in single inheritance languages.

A

code reuse

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

Can you instantiate a trait on its own?

A

No.

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

Traits are the application of class members without requiring __.

A

inheritance

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

How do you insert multiple traits into a class?

A

As a comma-separated list.

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

What happens when two traits insert a method with the same name?

A

A fatal error is produced.

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

The ‘as’ syntax can also be used to adjust…

A

…the visibility of a method.

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

Static variables can be referred to in trait methods, but cannot be __ _ _ __.

A

defined by the trait

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

Can traits define static methods for the exhibiting class?

A

Yes.

17
Q

Avoid using ‘as’ on a…

A

…__construct() method.

18
Q

How can you iterate through all visible properties in a class?

A
$class = new MyClass();
foreach($class as $key=>$value) { ... }
19
Q

How can you iterate through non-visible properties in a class?

A

Within the class definition:

foreach($this AS $key=>$value) { … }

20
Q

Can a property be declared as final?

A

No. Only classes and methods.