30
1
using System;
2
// Base class (parent class)
3
public class Animal {
4
public string Name;
5
6
public void Eat() {
7
Console.WriteLine($"{Name} is eating.");
8
}
9
}
10
11
// Derived class (child class)
12
public class Dog : Animal {
13
public void Bark() {
14
Console.WriteLine($"{Name} is barking.");
15
}
16
}
17
18
class ConsoleApp {
19
static void Main() {
20
// Creating an instance of the derived class
21
Dog myDog = new Dog();
22
myDog.Name = "Buddy";
23
24
// Using inherited method from the base class
25
myDog.Eat();
26
27
// Using method specific to the derived class
28
myDog.Bark();
29
}
30
}
Cached Result
九把刀你愛小三嘛?(y/n)
>