Java Novice Note 17 parameters

Source: Internet
Author: User

Package Com.yfs.javase;public class Paramdemo {public static void main (string[] args) {int a = 3, B = 5;change (a); System.out.println ("a =" + a  + "  B =" + B); Point P = new Point ();p. x = 10;p.y = 20;change (p); System.out.println ("p.x =" + p.x  + "  p.y =" + p.y);} public static void Change (point P) {//reference pointing to  is an object int c = p.x;p.x = P.y;p.y = C;} public static  void change (int a, int b) {//local variable  passed in is numeric System.out.println ("================"); System.out.println ("|  | | | | | | A = "+ a  +"  B = "+ B +" | | | | | | "); int c = A;a = B;b = C; System.out.println ("|  | | | | | | A = "+ a  +"  B = "+ B +" | | | | | | "); System.out.println ("================");}} Class Point {int x;int y;}

1.Person

Package Com.yfs.javase;public class Person {public person () {System.out.println ("javase. Person  * * * ");}}

2. Other person

Package Com.yfs.javase.other;public class Person {public person () {System.out.println (' other '). Person object ... ");}

3.Person Test

Package Com.yfs.javase.other;import Com.yfs.javase.person;public class Persontest {/** * @param args */public static void Main (string[] args) {person P1 = new person (); Com.yfs.javase.other.Person P2 = new Com.yfs.javase.other.Person ();}}

4.default

Package com.yfs.javase.other; Class Defaultdemo {}  class other {    }    /*public*/class Demo {    }

5. Public class

Package com.yfs.javase.other;//A Java file can have only one public decorated class//class with the same name as the file public/*final*/class Publicclass {private String name ;p ublic int age;protected char sex;int score; static final int id;//= 520;//only one copy of all objects shared static {id = 200;} Public Publicclass () {//id = 100;} The permissions of the method public final void Publicmethod () {//id = 350;} private void Privatemethod () {Protectedmethod ();} protected void Protectedmethod () {}    /*default*/void Defaultmethod () {Protectedmethod ();}} /*default  public*/class Defaultclass {}

6. Testing

Package com.yfs.javase.other;//under Common class AccessTest1 {public static void main (string[] args) {Publicclass pc = new Publicclass ();p c.publicmethod ();//pc.privatemethod (); Private methods cannot access Pc.protectedmethod ();p c.defaultmethod ();    Pc.age =;    Pc.score = 90;}}

7. Out-of-package testing

Package Com.yfs.javase;import com.yfs.javase.other.publicclass;//under different packages public class AccessTest2 {public static void main (string[] args) {Publicclass pc = new Publicclass ();p c.publicmethod ();//pc.privatemethod (); Private method cannot access//pc.protectedmethod (); The protected method cannot access the//pc.defaultmethod ();d Efautl method cannot access}}class child  extends Publicclass {public void Test () {// Privatemethod ();p rotectedmethod ();//subclass can access//defaultmethod ();//different packages cannot access}//@Override//public final void Publicmethod () {////TODO auto-generated method stub////}}

Java Novice Note 17 parameters

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.