Java method signature

Source: Internet
Author: User

The name of the method and the list of references become signatures of the method. Note that the method signature does not contain the return type of the method. In this paper, we understand the true meaning of the list by testing and how the return value of the method should be related to the return value of the method in the parent class when overriding the method in the inheritance.

Here are three helper classes:

Package Methodsign;public class Ancestor {}

Package Methodsign;public class Parent extends Ancestor {}

Package Methodsign;public class Other {}

The following is a test class. The test results are described in the gaze:

Package methodsign;/** * Test Method signature * Method name and reference list is called method signature * @author Yuncong * */public class Person {private String name;private String gender;private int age;public person () {//TODO auto-generated Constructor stub}/** * by constructor 1 and constructor 2 cannot exist at the same time. The list of parameters for the method signature is detailed in the type listing of the reference number. * by constructor 1 and constructor 3 can exist at the same time, it is known that the parameter type list of the method signature is also related to the order of the parameter type, that is, * even if the method is in parentheses with the same number of parameters and type, only the order of the type of the parameter is different, but also a different parameter type list *///constructor 1public Person (string name, String gender, int.) {super (); this.name = Name;this.gender = Gender;this.age = age;} Constructor 2public Person (string Gender, string name, Int. age) {super (); this.name = Name;this.gender = Gender;this.age = age;} Constructor 3public Person (string name, int age, string gender) {super (); this.name = Name;this.age = Age;this.gender = gender;} Public Ancestor GetAncestor () {return new Ancestor ();}}

Package Methodsign;public class Student extends the person {/** * Method 1 is correct, method 2 is incorrect, and the method of overriding the parent class in the subclass is described. The return value of the method must be the same as the return value of the method in the parent class or a subclass of the method return value in the parent class *///method 1public parent GetAncestor () {return new parent (); Method 2public Other GetAncestor () {Return to new Other ();}}


Java method signature

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.