198k views
19 votes
Choose the 3 correct statements for the code below.

An object of the ActivationLayer class has a name attribute.
An object of the BaseLayer class has a size attribute.
print(FCLayer(42)) prints FullyConnectedLayer.
When creating an object of the ActivationLayer class, the size argument must be given.
When creating an object of the BaseLayer class, the name argument must be given.

Choose the 3 correct statements for the code below. An object of the ActivationLayer-example-1
User Youzef
by
4.4k points

1 Answer

6 votes

Answer:

True

False

True

False

True

Step-by-step explanation:

So I'll go through each statement and explain why or why not they're correct.

An object of the ActivationLayer class has a name attribute. So because ActivationLayer is inheriting the BaseLayer and it's calling super().__int__("Activation") it's going to call the BaseLayer.__init__ thus setting a name attribute equal to "Activation" for any ActivationLayer object that is initalized. So this is true

An object of the BaseLayer class has a size attribute. While it is true that FC layer is inheriting from BaseLayer and it has a size attribute, this does nothing to change the BaseLayer class. So any object initialized to a BaseLayer object will only have the instance attribute "self.name". So this is false

print(FCLayer(42)) prints FullyConnectedLayer. So whenever you print an object, it tries to convert the object to a string using the __str__ magic method, but if that wasn't defined it then tries the __repr__ method, which the FCLayer class technically doesn't define, but it inherits it from the BaseLayer class. And since whenever you define an FCLayer object it calls super().__init__ with "FullyConnected", which will then be assigned to the instance variable self.name, it will print "FullyConnectedLayer". So this is true

When creating an object of the ActivationLayer class, the size argument must be given. This is true, because the size is a parameter of the __init__ method of ActivationLayer, it is not an optional parameter, and is something that must be passed otherwise an error will be raised. So this is false

When creating an object of the BaseLayer class, the name argument must be given. This is not true, because name is a default argument. This means if you do not pass an argument for name, then name will equal an empty string

User Saverio
by
4.6k points