-7

I have wrote a print method which tell the user congratulates on their, but at the same time i have another field called Downloads, I wouls like to update the field downloads once the thr print method have been invoked, thanks and im using bluej

tatu_kabo
  • 29
  • 4

1 Answers1

2

instead of

int num;
 this.noOdDownloads = num;
 this.noOdDownloads = num + 1;

do

 this.noOdDownloads++;

your original program has two problems: 1) num is not instantiated, this is what the compiler will complain, and 2) even if you instantiated it, say with int num=0;, num is actually a local variable in the method. every time the method is run, the local variable is instantiated again and reset to 0. When you then assign its value to noOdDownloads, the latter is reset to 0 too.

gefei
  • 16,986
  • 6
  • 47
  • 64