Questions about Asp.net virtual methods, abstract methods, and interfaces

Source: Internet
Author: User

1. can abstract classes provide non-Abstract execution methods? What about interfaces?
A: The abstract class can be written as follows: CopyCodeThe Code is as follows: public abstract class
{
Public String getweburl ()
{
Return "jb51.net ";
}
Public abstract string getwebname ();
}
Public Class B:
{
Public override string getwebname ()
{
Return "";
}
}

Run: B = new B ();
Response. Write (B. getweburl ());
There is no error during compilation, but the interface itself can only contain members but not specific implementations, and abstract functions can only exist in abstract classes. Therefore, interfaces only have method signatures, but there is no specific implementation, it is not an abstract function, for example, C # copying code.
Interface IA
{
String getweburl ();
String getwebname ();
}
2. Must the members in the interface be implemented by their subclass?
A: An interface is a special case of an abstract class. Abstract functions must be overwritten and implemented by their subclasses.
Iii. Can virtual keywords be used in abstract classes?
A: No. The abstract class can only contain abstract methods and abstract accessors.
4. can abstract classes be instantiated?
A: No.

Related Article

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.