2013年11月18日星期一

A simple procedure, troubles come and see

public class GameTest {

public static void main (String args []) {
hunter h = new hunter ();
h.name = " Delong " ;
h.life = 100;
h.islife = true;
Monster m = new Monster ();
m.name = " zombie" ;
m.life = 80;
m.islife = true;
h.fight (m);


}
}

class hunter {

int life;
String name;
boolean islife;

public void fight (Monster monster) {


System.out.println ("------------->" + name + " waving arms " + " to kill " + monster.name + " < --------------- " ) ;
monster.injured ();


}
public void show () {


System.out.println ("*************" + " hunter's life:" + life + "islive:" + islife + " ************ " ) ;
}
}
class Monster {
int life;
String name;
boolean islife;


public void injured () {
System.out.println ("*************" + name + " yapping , ooo, ooo " + " ******* ****** " ) ;

life = life-20;

}

public void show ()
{

System.out.println ("*************" + " Monster 's life:" + life + "islive:" + islife + " ************ " ) ;

}
}
public void fight (Monster monster) this method , Monster monster What does it mean ? Is materialized it ? Or how ?
------ Solution ---------------------------------------- ----
Monster monster = new Monster ();

In the above statement, the equal sign ( = ) is called the left define a reference variable , monster called reference variables ( some people call it references ) ;
called right-hand side Monster class object ( some people call instance ) .

Obviously, you said that the reference variable is called to receive an object ( also called instances ) references ( also called address ) .
professional point , you can call it a formal parameter ( also called parameters ) .

Here is a simple example :
hands of one person holding a balloon. Monster object is that the balloon , and you said that the monster ( reference variable ) is the hands.



I hope my answer can help you.
------ For reference only -------------------------------------- -

Thank you . Although I have to get to know it. But still thank you so seriously !

没有评论:

发表评论