[* Original *] 2 interview questions-communicate with BoyLee

Source: Internet
Author: User
Tags define abstract

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;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.