0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C#】Abstractクラスについて

Last updated at Posted at 2025-09-06

Abstractクラスについての処理です。これから肉付けしていきます

Program.cs
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        
        Ice ice = new Ice();
        
    }
}

public abstract class Attack
{
    public Attack()
    {
        Console.WriteLine($"{Name()}攻撃");
        Console.WriteLine($"相手に{Power()}ダメージ");
    }
    
    protected abstract string Name();
    protected abstract int Power();
}

public class Ice:Attack
{
    public Ice():base()
    {
        Console.WriteLine("相手は氷漬けになった");
    }
    
    protected override string Name()=>"氷";
    protected override int Power()=>30;
}

サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?