A
A
Alexander Muradov2020-05-26 03:02:44
Python
Alexander Muradov, 2020-05-26 03:02:44

How, when calling a method in a method of a child class, to pass an object of the parent class?

I'm new to Python OPP so don't judge too harshly. There is a situation:
class A()
class B(A)
class C(A)
5ecc5adde6bbf400744317.png
I call a method of class C from class B and pass object B, but since class C is a child of class A, when calling a method of class B, pass object A. How being in a method of class B, call a method of class C passing an object of class A, which is the parent of B. How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-05-26
@trapwalker

Well, you have porridge in ... understanding. Did you understand what you wrote?
At you inheritance contradicts the drawn diagram.

class A()
class B(A)
class C(A)

What do you mean by passing an object to a method?
If the methods are not class methods, then they are called on objects, not on classes.
If you are trying to call a method of class C from an object of type B, then you will fail, because both B and C are direct descendants of A.
Describe your classes in code as is, otherwise nothing is clear from this rambling exposition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question