educative.io

Educative

Quiz questions 4 and 3

1)
In question 4 it says two associated classes cannot exist independently. But, how is that? For example, a pet dog and its owner are 2 classes that are associated. But they also do exist independently.

2)
In question 3 it says when two classes are in aggregation relationship it has only one parent. But that is not true. A child class can have more than one parentreferred this link%20and%20Student%20(child).)
Please help. Thank you.

Hi @Harika_Macharla,

Question 1
Yes, you are right that they can exist independently in code, but how can an owner be an owner without owning a pet? Or, how can a pet be a pet without having an owner? Here, we are not just talking about the code itself, but the common logic behind writing the code as well.

Question 2
The child can have two parent classes but only one parent object.

We hope Educative has inspired you to further your learning.

Best Regards,
Waleed | Developer Advocate
educative.io

Thank you for the clarification.

1 Like

What do you mean that a child can only have one parent object? I can create two parent objects with child object c (see below)

class Country:
def init(self, name=None, population=0):
self.name = name
self.population = population

def printDetails(self):
    print("Country Name:", self.name)
    print("Country Population", self.population)

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

def printDetails(self):
    print("Person Name:", self.name)
    self.country.printDetails()

class Item:
def init(self,name,country):
self.name=name
self.country=country

def printDetails(self):
  print(self.name, 'is from')
  self.country.printDetails()

c = Country(“Wales”, 1500)
p = Person(“Joe”, c)
t=Item(“chocolate”, c)

p.printDetails()
t.printDetails()

deletes the object p

del p
print("")
c.printDetails()

I have the same thoughts. One could simply write

p1 = Person(“Joe”, c)
p2 = Person(“Mama”, c)

And now c has two owner objects (of the same class)