methods - Java: Parameter list without comma -


i came across method parameter list parameter not separated comma , no declaration of variable type:

public int comparewith(choice anotherchoice){ 

later these parameters called without further declaration inside body in if-else statement in combination method:

if ((this.type == 0)&&(anotherchoice.gettype() == 1)){         return -1; 

this brief summary of entire class:

public class choice {  private int type;    public choice(int type) {     //initialize "type" instance varialble     this.type = type; }    public int gettype() {     return type; }   public int comparewith(choice anotherchoice) {    choice choice1 = new choice(0);    choice choice2 = new choice(1);    if ((this.type == 0)&&(anotherchoice.gettype() == 1)){         return -1; 

the program goes on. don't link between anotherchoice, gettype() , choice2. task in online course , program works intended, don't know why.

i'm guessing you're new programming, i'll give quick explanation of what's going on. if i've missed point of question entirely, i'm sorry.

this line:

public int comparewith(choice anotherchoice){ 

is part of choice object. takes choice object , compares itself. ...or @ least, that's expect. code provided:

public int comparewith(choice anotherchoice) {    choice choice1 = new choice(0);    choice choice2 = new choice(1);    if ((this.type == 0)&&(anotherchoice.gettype() == 1)){         return -1; 

is incomplete , have no idea choice1 , choice2 supposed doing. code expect see more like

public int comparewith(choice anotherchoice) {    if (this.type == anotherchoice.gettype())         return 0;    return -1; } 

or that.

does help?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -