I have summed up three: There are a lot of estimates, just feel these few more commonly used just. You are welcome to discuss the following article:
code doesn't explain.
Be aware of how the code is stored in your computer. Take this code as an example: first you need to know that you perform instances such as Stu[0]=new Student ("John", 18), which creates a Student space inside the heap space to hold various attributes, and stu[0] stores an address that points to that space. So traversal is this address, and as Student stu = new Student ("name", age); This stu is a reference, and you print it out to print this address, and if you print a property, that object has a lot of properties, Which attribute does the system want to print? (Example one, instance II)
Example One:
public class Student {
private String name;
private int age;
Public Student (String name, int age) {
this.name=name;
this.age=age;
}
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
public int getage () {return age
;
}
public void Setage (int age) {
this.age = age;
}
public void Show () {
System.out.println (name+ "\ t" +age);
}
public static void Main (string[] args) {
Student [] Stu =new student[5];
Stu[0]=new Student ("John");
Stu[1]=new Student ("Zhao Si",);
Stu[2]=new Student ("Harry");
Stu[3]=new Student ("Old Six");
Stu[4]=new Student ("Old Seven");
for (int i=0; i<stu.length; i++) {
stu[i].show ();
}
}
}
Example Two:
public class Student {
private String name;
private int age;
Public Student (String name, int age) {
this.name=name;
this.age=age;
}
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
public int getage () {return age
;
}
public void Setage (int age) {
this.age = age;
}
public static void Main (string[] args) {
Student [] Stu =new student[5];
Stu[0]=new Student ("John");
Stu[1]=new Student ("Zhao Si",);
Stu[2]=new Student ("Harry");
Stu[3]=new Student ("Old Six");
Stu[4]=new Student ("Old Seven", 22);
for (int i=0; i<stu.length; i++) {
System.out.println (stu[i].getname () + "\ T" +stu[i].getage ());}}}
Example three: Use to rewrite ToString () is at the bottom of the class to rewrite to in the MyEclipse shortcut key prompt, can be quickly typed
public class Student {
private String name;
private int age;
Public Student (String name, int age) {
this.name=name;
this.age=age;
}
Public String GetName () {return
name;
}
public void SetName (String name) {
this.name = name;
}
public int getage () {return age
;
}
public void Setage (int age) {
this.age = age;
}
public static void Main (string[] args) {
Student [] Stu =new student[5];
Stu[0]=new Student ("John");
Stu[1]=new Student ("Zhao Si",);
Stu[2]=new Student ("Harry");
Stu[3]=new Student ("Old Six");
Stu[4]=new Student ("Old Seven");
for (int i=0; i<stu.length; i++) {
<span style= "White-space:pre" > </span>system.out.println (Stu[i]);
}
@Override public
String toString () {return
"Student [name=" + name + ", age=" + Age + "]";
}
}