Super Simple example of the relationship between Java PACKET CLASS and variables

Source: Internet
Author: User

One, package packet is a folder, the package under the class to each other to access such as a file.

Second, the class interior is equivalent to a Delphi CALSS, static functions can only access static functions.

Package mainpack;

public class Mainprg {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Human Aman=new Human ();
Human Bman=new Human ();
Aman. Createnewman ("Zhang San", +, True);
Bman. Getaman ();
Showstr (Bman.name);
}

private static void Showstr (String str) {
System.out.print (str);
}

}

Static variables are equivalent to a public access space, and new instances can still access data from other instances.

Package mainpack;

public class Human {
Static String Name=null;
static int age=0;
Static Boolean sex=true;

public void Createnewman (String nn,int Aa,boolean ss) {
Name=nn;
AGE=AA;
Sex=ss;
}

Public human Getaman () {
Human Hh=new Human ();
Hh.name=name;
Hh.age=age;
Hh.sex=sex;
return HH;
}

}

Results show Zhang San

Variable minus static, showing null

Super Simple example of the relationship between Java PACKET CLASS and variables

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.