08 Inheritance - Inheritance CMPUT*175 Objec6ves...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Inheritance CMPUT 175
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Objec6ves To explore classes and objects further To design another mul6class applica6on To introduce the concept of inheritance To implement a graphical simula6on using objects
Image of page 2
What we know already A single class can have many instances An object is an instance of a class Each instance is created by __init__ e.g. nemo = Fish() Each instance remembers what class it is instance of; e.g . isinstance(nemo, Fish) The __class__ aJribute is created automa6cally; e.g. nemo.__class__ == Fish
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Find the aJribute To find the value of an aJribute (e.g. myobj.__name ) Python) looks: 1. First, in the instance (referenced by myobj ) 2. If not found there, in the class the instance was derived from (i.e. Fish ) 3. If not found there, in the parent class The parent class is specified in parentheses aSer the class name (e.g. class Fish(Animal) )
Image of page 4
The class hierarchy Every class has at least one parent class It is oSen called the ISUA rela6onship The ISUA rela6onship is oneUway A class know its parent class, but the parent class does not track its child classes This is recorded in the __bases__ aJribute All the classes form a hierarchy
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Using Inheritance If a class is created with a parent class, then it can reuse the methods in the parent class
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern