asp.net virtual method, abstract method, interface question _ Practical skills

Source: Internet
Author: User
Can you provide a non-abstract execution method in an abstract class? What about the interface?
A: Abstract classes can be written like this:
Copy Code code as follows:

Public abstract class A
{
public string Getweburl ()
{
return "Jb51.net";
}
Public abstract string Getwebname ();
}
public class B:a
{
public override string Getwebname ()
{
Return to "cloud-dwelling community";
}
}

Run: b b = new B ();
Response.Write (B.getweburl ());
Compilation passes without errors, and the interface itself can contain only members but not concrete implementations, and abstract functions can exist only in abstract classes, so only the signature of the method in the interface, but not the specific implementation, and not abstract functions, for example: C # copy Code
Interface IA
{
String Getweburl ();
String Getwebname ();
}
Second, does the member in the interface have to be implemented by its subclass?
A: Interfaces are a special case of abstract classes, and abstract functions must be overridden by their subclasses, and the members of an interface must be implemented by their subclasses as well.
Can I use the virtual keyword in an abstract class?
A: No, abstract classes can contain only abstract methods and abstract accessors.
Can abstract classes be instantiated?
A: No, you can't.

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.