A simple example shows the relationship between java packet class and variables. javapacket
1. PACKET is a folder, and the CLASS in the package accesses each other as a file.
2. The class 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 ("James", 21, true );
Bman. GetAman ();
Showstr (bman. name );
}
Private static void showstr (String str ){
System. out. print (str );
}
}
3. static variables are equivalent to a public access space. New instances can still access data of 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;
}
}
The result shows michael Jacob.
The variable is removed from static and the display is null.
In java, what is the higher priority of local variables when they have the same name? It is better to give a simple example,
Public class test (){
Public static void main (string [] args ){
Int I = 3;
System. out. println (I );
}
Public void face (){
For (int I = 0; I <5; I ++ ){
System. out. println (I );
}
}
}
The result is 1 to 5. When two variables are named again, the priority of local variables is higher...
What is the relationship between classes and classes in java?
External class, internal class, Anonymous class, external class is the class A {} class B {}, internal class: class A {class B {}}, B can directly use the member variables of the class containing it. The internal class cannot be called by classes other than the inclusion class; there is also an anonymous class, the internal class classA {new {}} also omits the definition class name to directly define the method and use. This applies to code that is relatively simple and this class does not need to be called by other classes.