SampleScript.cs
using UnityEngine;
namespace Assets.Samples.Sample3
{
public class SampleScript : MonoBehaviour
{
private void Start()
{
Base overrideExample = new OverrideExample();
Base hidingExample = new HidingExample();
print(quot;{overrideExample.Name} {hidingExample.Name}");
}
}
}
Base.cs
namespace Assets.Samples.Sample3
{
public abstract class Base
{
public virtual string Name => nameof(Base);
}
}
OverrideExample.cs
namespace Assets.Samples.Sample3
{
public class OverrideExample : Base
{
public override string Name => nameof(OverrideExample);
}
}
HidingExample.cs
namespace Assets.Samples.Sample3
{
public class HidingExample : Base
{
public new string Name => nameof(HidingExample);
}
}
2 comments