1. In reference to the following image, which of these statements is true?
2. In the following image, the red Toyota is ….
3. Blue' in this example is a …..
4. The values (attributes) assigned by the constructor to the class members is used to create an ……………...
5. Here we have a class and an object both being used. What is the output of this code?
6. setattr(obj,name,value) could be used to set an attribute. If attribute doesn’t exist, …….
7. What is getattr() used for?
8. What is the output of the following code?
9. In the following code, what is the class, what is the object, and what is happening on the last line?
10. ……………………..is the OOP word for creating an instance of a class.
11. Which piece of code creates an empty class?
12. Analyse the following code. Which option correctly creates an object called student1?
13. In the following code, what will the output be?
def __init__(self,name,test_score): #this init method is the first method to be invoked when you create an object
#ensure you initialise all your attributes in the init method
#=======creating a method to see if the student has met their target
#the self is a default parameter that the methods of your class accept, in order to use the attributes of your class
print("Target met, Well done!")
print("Target not achieved")
student1=Student("Jonathan",21) #the process of creating an object is called instantiation.
Jonathan, 21, Target met, Well done!
Jonathan, 21, Target not achieved
Error message - as there is no method to print the target
14. In the following code, point out the classes and objects.
from turtle import*
#self is how we refer to things in the clas from within itself. .self is the first parameter in any function defined inside a class
#to access functions and variables inside the class, their name must be preceded with self and a full-stop (e.g. self.variable_name)
self.radius=radius #circles need a radius in order to be defined
canvas = Screen()
turtle = Turtle()
self.turtle.goto(self.x,self.y) #go to (x,y+radius)
self.turtle.dot(self.radius) #dot takes the circle diameter as a parameter (size)
#Specify width and height below e.g. 100,200
Planet' is the class, and there are two objects (planet1 and planet2)
There are two classes (planet1 and planet2) and one template object 'Planet'
There are three classes (planet, planet1 and planet2)
None of the above
15. The following code is in VB.Net. Can you follow the logic to predict the output?