First, let's see why @ override is used.
@ Override is not a standard for Android, but an annotation added in Java 5.
Http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/override.html
@Target(value=METHOD)@Retention(value=SOURCE)public @interface Override
Indicates that a method declaration is intended to override
Abstract Class Base
{
Public Virtual VoidWork ()
{
MessageBox. Show ("Base class -- start work");
}
Public Virtual VoidOutwork ()
{
MessageBox. Show ("Base class -- off duty");
}
Public abstract void pay ();//To declare an abstract method, the quilt class new or override must be required. The abstract method can be declared only when the class is abstract.
}
Class Employee:Base
{
Public New VoidWork ()
{
MessageBox. S
Override specifier
You can use the Override keyword to specify a member function that overrides a virtual function in a base class.Grammar
Function-declaration Override;
NoteOverride is context-sensitive and has special meaning only when it is used after a member function declaration, otherwise it is not a reserved keyword.Using
What is the point of using the new and override keywords in a method on a derived class, you can find the answer through a series of questions. Look at the code first:1 class Program2 {3 Static voidMain (string[] args)4 {5Child C =NewChild ();6 C.func ();7 8 Console.read ();9 }Ten } One A classParent - { - Public voidFunc () the { -System.Console.WriteLine ("Parent"); - } - } +
object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked".If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types.is called a method's overload (overloading). The overloaded method is to change the type of the return value.The difference between overload and overrideOverride (override
I thought it was not difficult, but I studied it carefully and found that it was not the case. It was a bit complicated and special record.
The information found is as follows:
1. Let's talk about the three keywords new, virtual, and override in C #.
2. Learn from each other in a gentle manner: differences between new and override, and differences between virtual and abstract methods
3.
Abstract, virtual
1. Comparison between override and new during method overwrite in C #
The override keyword in C # is used to overwrite the virtual method and abstract method;
In C #, The New Keyword is used to overwrite the "normal" function of the parent class in the derived class (that is, in the context of non-virtual functions and non-Abstract Functions)
Below isCodeExample: (for the usage of
@Override Annotations are annotations that act on the source code and are used to indicate that the method of the annotation overrides the method of the parent type, but this annotation differs between 1.5 and 1.6 and later. 1.5, it can only be used when inheriting a class, overriding a method in the parent class, and when implementing a method in an interface, it is not possible to use the annotation, starting from 1.6, to support methods that implem
1.Parent class: public virtual string ToString () {return "";}Subclass: public override string ToString () {return "B ";}2.In the same class or in the parent-child relationship class:Public string ToString () {return "";}Public string ToString (int id) {return id. ToString ();}
Override is a virtual method used to override the base class. In this way, a new metho
1). Overwrite (override)Override is overriding (overriding) a method to implement different functions, typically for subclasses that override (re-implement) the parent class when inheriting the parent class, implementing different requirements.Override (Overwrite) the rule:1. The overridden method must be either Virtual,abstract or
New
The New Keyword can explicitly hide members inherited from the base class. Hiding inherited members means that the derived version of the member replaces the base class version. That is to say, the method used in the derived class is to call the method with the new keyword.New definitionInstead of the base class method.Hidden members are allowed without the new modifier, but warnings are generated. Explicitly hiding a member with new removes this warning and records the fact that the me
New
The New Keyword can explicitly hide members inherited from the base class. Hiding inherited members means that the derived version of the member replaces the base class version. That is to say, the method used in the derived class is to call the method with the new keyword.New definitionInstead of the base class method.Hidden members are allowed without the new modifier, but warnings are generated. Explicitly hiding a member with new removes this warning and records the fact that the membe
The specific usage of new, override, virtual in C #
Class Program{static void Main (string[] args){Testshape ();Console.WriteLine ("Testshape End =============" + Environment.NewLine);Testderive ();Console.WriteLine ("Testderive End =============" + Environment.NewLine);Testderive2 ();Console.WriteLine ("Testderive2 End =============" + Environment.NewLine);Console.readkey ();}
private static void Testshape (){system.collections.generic.listSh
Before c++11, there was no inheritance control keyword. Disabling further derivation of a class is possible but tricky. To prevent users from overloading a virtual function in a derived class, you have to think backwards.C + + 11 added two inheritance control keywords: override and final. Override ensures that overloaded functions declared in a derived class have the same signature as the virtual function o
Abstract, virtual, override, and new are the keywords of the four modifier Methods Commonly Used in the class inheritance relationship, which are briefly summarized here.
1. commonly used Chinese names: Abstract abstract method, virtual method, override base class method, new hide base class method, override and new are sometimes called
Rectangle and Ellipse, has their own overridden (override) member function Rectangel::D raw and Ellipse::D RawNew Rectangle; Ps1->draw (); // calls Rectangle::d rawnew Ellipse; Ps2->draw (); // calls Ellipse::d raw Of course, if you want to call a member function of a base class, you can add a class scope operator:// calls Shape::d Raw // calls Shape::d Raw1.2 General virtual functionsBefore the function declaration is appended with the virtu
The C # language is specially designed so that version control between the base classes and derived classes in different libraries can continue to develop and maintain backward compatibility. This has many meanings. For example, this means that introducing a new member with the same name as a member in the derived class in the base class is fully supported in C # and will not cause unexpected behavior. It also means that the class must explicitly declare whether a method needs to
@Override is pseudo-code, which means rewriting (not writing, but some Ides will report warning), but the following benefits are written:1, can be used as a comment, easy to read;2, the compiler can give you to verify @override the following method name is all in your parent class, if there is no error. For example, if you do not write @override, and your next me
@ Override is already available in JDK 5, but there is a small bug that does not support interface implementation.JDK 6 fixes this bug. You can add @ override to both the method override of the parent class and the implementation of the interface.I think this problem has certainly plagued many people, and I am no exception. New companies use something more or les
In C #, new and override are two frequently used keywords in inheritance, but they are often easy to confuse the functions of these two keywords.
New
C # The new Keyword indicates hiding. It indicates that an attribute or function with the new keyword will hide the Same Name attribute or function of the base class for this class and the inherited class.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
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.