Java parameter Passing value

Source: Internet
Author: User

The value of the basic data type parameter, which is the base data type

classcomputer{intAddintXinty) {       returnx+y; }} Public classExample4_6 { Public Static voidMain (String args[]) {computer COM=Newcomputer (); intm = 100; intn = 200; intresult =Com.add (m,n);     SYSTEM.OUT.PRINTLN (result); }}

Reference type parameter passing value, parameter is a class

Battery.java

 Public class Battery {    int  electricityamount;    Battery (int  amount) {        = amount;    }}

Example4_7.java

 Public class example4_7 {   publicstaticvoid  main (String args[]) {      new Battery (+);      System.out.println ("The storage capacity of the Nan Fu battery is:" +nanfu.electricityamount      ); New Radio ();      SYSTEM.OUT.PRINTLN ("Radio starts using Nan Fu Battery");      Radio.openradio (NANFU);      System.out.println ("The current storage capacity of the Nan Fu battery is:" +Nanfu.electricityamount);}   }

Radio.java

 Public class Radio {    void  Openradio (Battery Battery) {        = battery.electricityamount-10;    }} 

Java parameter Passing value

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.