File size: 1,073 Bytes
99a41ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Class inheritance example for testing AST parsing."""

class Animal:
    """Base animal class."""
    
    def __init__(self, name, species):
        self.name = name
        self.species = species
        self.is_alive = True
    
    def speak(self):
        return "Some generic animal sound"
    
    def eat(self):
        return f"{self.name} is eating"


class Dog(Animal):
    """Dog class inheriting from Animal."""
    
    def __init__(self, name, breed):
        super().__init__(name, "Canine")
        self.breed = breed
        self.is_trained = False
    
    def speak(self):
        return "Woof!"
    
    def fetch(self):
        return f"{self.name} is fetching the ball"
    
    def train(self):
        self.is_trained = True


class Cat(Animal):
    """Cat class inheriting from Animal."""
    
    def __init__(self, name, color):
        super().__init__(name, "Feline")
        self.color = color
        self.lives_left = 9
    
    def speak(self):
        return "Meow!"
    
    def climb(self):
        return f"{self.name} is climbing"