Kursinnhold
Object-Oriented Programming in Python
Object-Oriented Programming in Python
1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism
Challenge
Note
Private methods and attributes of the parent class are not available in the child's class.
The Animal
class:
class Animal: def __init__(self, name = None, age = None): self.__name = name self.__age = age def move(self): print('Animal is moving...')
Oppgave
Swipe to start coding
- Create a class
Cat
that inherits theAnimal
class. - Create the
eat
method. - Create a
5
kg10
years old'Lola'
cat. - Move the cat (using the
move()
method from theAnimal
class). - 'Feed' the cat (using the
eat()
method from theCat
class).
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 2
Challenge
Note
Private methods and attributes of the parent class are not available in the child's class.
The Animal
class:
class Animal: def __init__(self, name = None, age = None): self.__name = name self.__age = age def move(self): print('Animal is moving...')
Oppgave
Swipe to start coding
- Create a class
Cat
that inherits theAnimal
class. - Create the
eat
method. - Create a
5
kg10
years old'Lola'
cat. - Move the cat (using the
move()
method from theAnimal
class). - 'Feed' the cat (using the
eat()
method from theCat
class).
Løsning
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 2