17 - Past Paper Simulation (OOP)

 1. Go through the following presentation and create the class (with attributes and methods shown). Select "Yes", when complete.



 2. Classes are used in Object Orientated Programming. Describe what is meant by a class? (3 mark)

 3. One of the pillars of OOP is Inheritance. Desribe what this term means. (3 marks)

 4. Name three other features of Object Orientated Programming (not including Inheritance) (3 marks)

 5. In the following code snippet, how many attributes can you count? (1 mark)

 6. What is the name of the method in the above class definition? (1 mark)

 7. Write a line of code that creates a new instance of Child (called mychild1) for a child with age 11 named "Joseph" (1 mark)
Assume you have a class called 'Child' with the required constructor attributes of 'name' and 'age'

 8. What is happening on line 1 of this program (class Teeanger(Child) (2 marks)

 9. Discuss the advantages and disadvantages to the team of developers of using OOP over procedural programming. You should refer to inheritance, encapsulation and polymorphism in your answer.(6 marks)
A software development company is building an operating
system for a mobile phone that is in the process of being

The code is written using an object-oriented programming
 (OOP) language. In one past paper (OCR) this is a 9 mark question.

 10. Analyse the code below. What is happening on the second last line? (1 mark)

 11. Referring to the previous question and the code snippet. What is the output of the last line? callum.isHappy? (1 mark)

 12. Analyse the following code. You'll notice that the object callum has been created based on the Teenager class. What is the output of callum.isSad()? (1 mark)
#What this program does: Create a Class called Child
#'Constructor' (although not called this in Python) requires name and age to instantiate an object from this class
#Attributes such as sad,hunger and intelligence are set to 0
#A method (is Sad?) is created and tells us if the percentage of 'sad' is above 90%!
class Child:
      def __init__(self,name,age): #this init method is like the constructor
          #initialise all your attributes

          #let's add an attribute to the parent class
      #=======creating a method called speak ("Hello there")
      def speak(self):
            print("Hello there")
      #=======creating a method to see if the student has met their target
      def isSad(self):
         #the self is a default parameter that the methods of your class accept, in order to use the attributes of your class
        if self.sad>=90:
            print("Not very happy -needs some play time!")
            print("Seems happy enough!")

class Teenager(Child): #inherits from Child - all the attributes and methods
      def __init__(self,name,age): #this init method is like the constructor
          #initialise all your attributes

      def speak(self):
            print("Hello there")
            print("I am always grumpy and don't get out of bed!") #an additional print statement in this method!
      def isHappy(self):
            if self.sad<30:
                  print("SAD SAD SAD")



  Seems happy enough

  Not very happy -needs some play time!


 13. Explain the difference between a HTML id attribute and a HTML class attribute. (2 marks)

 14. Inheritance is when a class takes on the methods and attributes of a parent class. The inheriting class may ______ some of these methods / attributes and may have additional extra methods and attributes of its own.

 15. ______________ is the process of keeping an object's attributes private so they can only be accessed and changed via public methods. Polymorphism means that objects of different types can be treated in the same way. (2 marks)