Java Magic Hall: annotation Usage--@Override

Source: Internet
Author: User

First, preface

There are now two classes of son and parent, and type son will override the GetName function of type parent. Unfortunately, due to the code of the agricultural idea, write the following code:

 Public class parent{  public  String getName () {     return'Parent " ;  }}  Public class Son extends parent{   public  String getnames () {     return'  Son";   }}

The above code compiles through and does not realize the realization error, tragedy happened ....

This is no longer the case with @Override annotations !

Second, @Override annotations

function : When a subclass function is added @Override , the function overrides the same signature function in the parent class, or the compilation fails.

Note: @Override only provides an accessibility hint function for overriding the parent class function, not a requirement for rewriting. Even without the annotation, the subclass function overrides the corresponding function of the parent class as long as the signature of the subclass function is the same as the parent class.

Respect the original, reprint please specify: http://www.cnblogs.com/fsjohnhuang/p/4040816.html ^_^ Fat Boy John

Third, reference

Http://www.cnblogs.com/liubiqu/archive/2008/06/01/1211503.html

Java Magic Hall: An explanation of annotation usage--@Override

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.