разбив его:
Это
public void giveTitle;int titleId;
{
this.playerTitle = titleId;
this.setAppearanceUpdateRequired(true);
}
Это просто lik е говоря, этот
public void giveTitle; // declare giveTitle
int titleId; // declare titleId
{ // brackets have no effect in this case.
this.playerTitle = titleId; // does not work because titleId has not
// been initialized
this.setAppearanceUpdateRequired(true); //
}
Как вы можете видеть, все, что вы делаете выше, объявляющий две переменные, которые не то, что вы хотите сделать. Вы хотели создать метод. Но с тем, что вы сделали public void giveTitle
, Вы получаете ошибку, потому что вы не можете объявить переменную с public void
То, что вы хотели было это
public void giveTitle(int titleId)
{ // here the brackets encasulate what's inside
this.playerTitle = titleId; // making them "belong" to the method.
this.setAppearanceUpdateRequired(true);
}
Просто добавьте эту скобку, вы превратили в mthod, который читает как этот
public void giveTitle(int titleId)
// a method named giveTitle with a parameter of an int titleId, will set this.title
// to the titleId passed into this method, also set the appearanceUpdateRequired to true
Он должен быть 'giveTitle()' с '()' – JoelFernandes
что вы пытаетесь сделать? Пытаться объявить метод? или некоторые переменные, за которыми следует блок кода? – rajneesh2k10