Today I asked BoyLee2 a question:
First, explain the similarities and differences between virtual methods, abstract methods, and interfaces;
Second, leave IDE and hand-write a simple WinForm Program (for example, including two neatly arranged text boxes and three buttons, and click the button to bring up the message box to display the text box content ), then compile and run the command line.
Answer to Question 1
Declare function: declared by virtual. It can be overwritten in the derived class. to override the method, it must be declared as virtual first.
Public class myclass
{
Public virtual int myint ()
{
Function body;
}
}
Class myclass1: myclass
{
Public override int myint ()
{
Function body 1;
}
}
Abstract classes and abstract Functions: abstract statements can define abstract methods in abstract classes. abstract methods do not have code to execute. The Derived classes must overwrite them and provide them with code execution.
Public abstract class myclass
{
Public abstract int myint ();
}
Public class myclass1: myclass
{
Public override int myint ()
{
Function body;
}
}
Interface Class: it is declared by the interface. It is a special abstract class. It is a combination of methods, attributes, events, and index characters. It has no fields, and its members have no execution mode and no constructor, operator Overloading is not allowed. interfaces and APIs do not have any access modifiers. They are always public and cannot be declared as virtual or static, the derived class inherited from the interface must implement all interface Imyinterface methods in the interface.
{
Void myfunction ();
String name
{
Get;
Set;
}
}
Class myclass: Imyinterface
{
Void myfunction ()
{
Function body;
}
String name
{
Get
{
Return name;
}
Set
{
Name = value;
}
}
}