This week's content is about class and subclass. I know the idea like subclass would inherit properties of classes, and may also alter or override method in parent class. However, when it comes to the tutorial which asks me to write an actual example using class and subclass, I lost myself at all. I think that is because I do not get in touch with some detailed examples.
We all see this in the course:
class A:
def g(self, n):
return n
def f(self, n):
return self.g(n)
class B(A):
def g(self, n):
return 2 * n
a = A()
b = B()
print("a.f(1): {}".format(a.f(6)))
print("b.f(1): {}".format(b.f(6)))
This example explain the idea of overriding very well, but it is too simple and is hard to apply.
Now I am trying to approach more resource online and learn by myself, but I am really worried about the future of my CSC148...
没有评论:
发表评论