One of the benefits of object-oriented programming is that it can hide complexity.
This is true, while using an object, we need to know how to use the object class but not how it works internally.
A class contains functions as well as the data that is used by those functions.
This is true as an class can contain functions as well as data that is used by those functions.
Constructor methods are required to initialize an object and destructor methods are required to destroy the object when no longer required.
This is false, a constructor is optional can be used to set initial values for an object and python automatically destroys any object if its reference count changes to a zero without needing a destructor.
A powerful feature of object-oriented programming is the ability to create a new class by extending an existing class.
This is true, we can extend a ’parent’ class to create a new ’child’ class and the new class has access to its functions and can override them if needed.
The _________ keyword defines a template indicating the data that will be in an object of the class and the functions that can be called on an object of the class.
class Pokemon():
def __init__(self, name, type):
self.name = name
self.type = type
def stringPokemon(self):
print(f"Pokemon name is {self.name} and type is {self.type}")
class GrassType(Pokemon):
# overrides the stringPokemon() function on 'Pokemon' class
def stringPokemon(self):
print(f"Grass type pokemon name is {self.name}")
poke1 = GrassType('Bulbasaur', 'Grass')
poke1.stringPokemon
poke1.stringPokemon()
poke2 = Pokemon('Charizard', 'Fire')
poke2.stringPokemon
poke2.stringPokemon()
Grass type pokemon name is Bulbasaur Pokemon name is Charizard and type is Fire
A child class can inherit functions from parent class and also override them.
Pokemon name is Bulbasaur and type is Grass Pokemon name is Charizard and type is Fire
The stringPokemon() functions is changed inside the GrassType class.
Grass type pokemon name is Bulbasaur Grass type pokemon name is Charizard
The stringPokemon() functions is only changed for GrassType class but remains unchanged in the original class.
Error because the extending class has a stringPokemon() function which already exists.
A class inherits functions from another class and override them in any way. Only the constructor class cannot be changed.
The child class does not need access to the all the inner workings in parent class.
False
The child class knows how to use the parent class and its functions but not its data and the inner workings. The "super" command can come in handy here.