- class
It can inherit to other class only one class.
The abstract class needs to use 'override'.
- interface
It can inherit to multiple class.
It does not need to use 'override'.
Ex)
1. Create the abstract class(parents). (uncompleted method)
2. Create the interface. Using with 'I' in accordance with the custom. (uncompleted method)
3. Create the class(children) which is inherited 1,2.
# 1
abstract public class A : MonoBehaviour
{
abstract public void Abc();
}
# 2
interface Ipart
{
void Bbc();
}
# 3
public class part : A, Ipart
{
public override void Abc() //'override'is must from abstract class
{
print("Abc");
}
public void Bbc() //interface class does not need to 'override'
{
print("Bbc");
}
}
'C#' 카테고리의 다른 글
namespace, struct, enum, property, indexer (0) | 2023.02.23 |
---|---|
private VS public VS protected VS abstract VS virtual (0) | 2023.02.21 |
delegate VS event (0) | 2023.02.21 |
array, ArrayList, List, Hashtable, Dictionary, Queue, Stack (0) | 2023.02.10 |
Parse, void, private, static, operation, conditional, Iteration, foreach (0) | 2023.02.10 |