Home>
I am studying c#, but I do not understand how to use abstract methods, so I will ask you a question.
https://qiita.com/igayamaguchi/items/e1d35db0a14a84bda452 of this site
I found the code below, but I understand that the talk method is an abstract method, so I can inherit it, but is it not possible to inherit since the walk method is not an abstract method?
I would also appreciate if you can tell me the difference between abstract classes and interfaces.
Thank you.
code
abstract class AbstractHuman
{
public void walk()
{
// walk process
}
// abstract method
abstract protected void talk();
}
class Human :Abstract Human
{
protected override void talk()
{
// talking process
}
}
-
Answer # 1
-
Answer # 2
You can only define abstract methods in abstract classes
Override Modifier-C# Reference | Microsoft Docs
Cannot override non-virtual or static methods
It was written.
Related articles
- c# - to call an abstract method in a function of an abstract class
- xcode - which class is the endediting() method?
- c# - unity: how do i get the "object in the scene" class?
- c# - how to output from another class to crystalreportviewer in form1
- c# - i want to pass the value of a field to another class as an argument
- c# - i want to call a method that has a return value with reactivecommand and get the result
- c# method of deleting the specified character string or later or method of extracting the character string to the left of the sp
- c# - get serializedobject of your own class with unity editor extension
- in c#, i want to give parents the methods and properties of the class that the generic contains
- c# - about learning method of data management in game programming
- c# - deadlock? bitmap class
- c# excel sheet name selection method in combo box
- c# - about changing the bool value in the method
- ruby - i want to know the reason for implementing it in a class method or module when solving an exercise
- c# - [wpf] [mvvm] about the parameter acquisition method at the time of screen transition
- python 3x - call method of child class from parent class
- Django adds a class method to the label tag generated by Form
- java - i can't find the main (string []) method in my class: infoweather and what should i do?
- python - when you want to use the method in class in another method but want to change the instance variable
Trends
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
A lot of information about the net has already rolled about "inheritance", "abstract class", and "interface" related to this question. If you search and understand them,Usually this kind of question does not occur..
If you haven't searched, let's do it first.
(The question doesn't mention anything you've looked up about "inheritance", "abstract classes", "interfaces", so it looks like you're not looking at anything)
If your search doesn't help, add as much as possible to your question what part of which source you didn't understand.
And, as I'll update, I am making a mistake when asking questions.
If you find something you don't understand, ask about the wording.
Let's see what inheritance is in C#.
(A reverse question, but reallyOnly abstract methods can be inheritedIs it? Please think)
Or, try to confirm that the hypothesis is correct by executing it.
(This is a reverse question, but if you can call the walk method from a Human instance, you can inherit it. Please check if the recognition is correct.)
Below are the commentary articles of both parties. Let's check each.
Abstract class
interface
By understanding both, you can sort out which parts are different and which ones have something in common in toukyoutaro's mind.
(Conversely, what do abstract classes and interfaces have in common? Think about them.)
To be honest, I don't think they have much in common. In other words, it is obvious that there are differences between the two, so I think you should read and understand each explanation.