11. Can I use Abstract Functions to override virtual functions in the base class?
A:
Yes
The new modifier must be explicitly declared to hide the implementation of the function in the base class.
Or an override modifier is added, indicating that the implementation of the function in the base class is overwritten.
Example:
Class BaseClass
{
Public virtual void F ()
{
Console. WriteLine ("BaseClass. F ");
}
}
Abstract class DeriveClass1: BaseClass
{
Public abstract new void F ();
}
// Thanks to watson hua (http://huazhihao.cnblogs.com/) for your guidance
// He reminded me that I can use this method to abstract and override the virtual method of the base class.
Abstract class DeriveClass2: BaseClass
{
Public abstract override void F ();
}
12. Can there be virtual functions in the seal class?
A:
Yes. The virtual functions in the base class are implicitly converted to non-virtual functions, but the new virtual functions cannot be added to the sealed class itself.
Example:
Class BaseClass
{
Public virtual void F ()
{
Console. WriteLine ("BaseClass. F ");
}
}
Sealed class DeriveClass: BaseClass
{
// The virtual function F in the base class is implicitly converted to a non-virtual function
// The new virtual function G cannot be declared in the seal class.
// Public virtual void G ()
//{
// Console. WriteLine ("DeriveClass. G ");
//}
}
13. What is an attribute accessor?
A:
Property accessors, including get accessors and set accessors, are used to read and write fields respectively.
The purpose of the design is to realize the encapsulation idea in object-oriented (OO. According to this idea, it is best to set the field to private. It is best not to set the field to public for direct access by the client caller in a delicate class.
In addition, note that attributes are not necessarily associated with fields.
14. can abstract be used with virtual? Can it be used with override?
A:
Abstract modifiers cannot be used with static or virtual modifiers.
Abstract modifier can be used with override. For details, refer to 11th.
Example:
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace Example14
{
Class BaseClass
{
Public virtual void F ()
{
Console. WriteLine ("BaseClass. F ");
}
}
Abstract class DeriveClass1: BaseClass
{
// Here, abstract can be used together with override
Public abstract override void F ();
}
Class Program
{
Static void Main (string [] args)
{
}
}
}
15. What members can an interface contain?
A:
An interface can contain attributes, methods, index indicators, and events, but cannot contain constants, fields, operators, constructors, and destructor, and cannot contain any static members.