Summary of J2SE Foundation-construction method

Source: Internet
Author: User

you are welcome to join the Big data (HADOOP, SPARK, data Mining) Learning Exchange Group, to share big data materials, communicate with each other as the main qq:550174771Overloading of methods

You can have multiple methods in a class that share the same name, as long as they have different parameters

parameter types differ in number of parameters

Package com.java2006;

Public class computer {

//Here static is the function of the method, in test can directly class name. Method access is not accessible by means of the new object

public static   int  sum ( int  a, int  b) {

return a+b;

}

public static   double  sum ( double  a, double  b) {

return a+b;

}

This defines a non-static method that is accessed through the new object

public int  add ( int  a, int  b, int  c) {

return A+b+c;

}

}

Define a test class

Package com.java2006;

Public class test1 {

Public static void main (string[] args) {

Here

int sum =computer. sum (1, 3);

System. out . Print (sum);

Double sum1=computer. sum (3.1, 5.4);

System. out . Print (SUM1);

Computer sum2= New computer ();

int aa=sum2.add (1, 2, 3);

System. out . Print (the value of "AA "+aa);

}

}

This article is from the "struggling small snail" blog, please be sure to keep this source http://sparkkang.blog.51cto.com/11242173/1755499

Summary of J2SE Foundation-construction method

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.