Object Oriented Programming

filler(58)
Published in
#coding
Words
261
Reading
2 min
7y
Listen to this post
~2 min

This is more difficult in Python and can really frustrate you.

Patience is the key and do not forget to practice.

Object oriented programming quiz

  • The property is created

a) Using the property decorator
b) Using the classmethod decorator
c) Making a class a subclass of property

Answer - a) property@property

  • What is the difference between a class method and a static method?

a) Class methods are passed the calling class, static methods aren't
b) Class methods are faster
c) Class methods are inherited, static methods aren't

Answer - a) refers to the class instance with cls or self

  • What are the usual parameter names for the calling instance and the calling class?

a) slf and cls
b) self and cls
c) self and class

Answer - b) self and cls ( it was also referred to in the previous question)

  • What method is called just before an object is instantiated?

a) create
b) del
c) init

answer - c) init
(__ is double underscore)

  • Fill in the blanks to make the egg attribute strongly private and access it from outside of the class.

class Test:
___egg = 7

t = Test()
print(t._Test____)

Answer - _egg = 7
t = Test()
print(t.Test
egg)

  • What is the automatic process by which unnecessary objects are deleted to free memory?

a) Garbage collection
b) Rubbish deletion
c) Bit-trash exfoliation

Answer - a) Garbage collection

  • class Person:
    def init(self, name):
    self._name = name

    property@property
    def name(self):
    return self._name


def name(self, value):
self._____= value

name.setter@name.setter - first-line answer
_name - second line answer

image source