java - returning a private static variable -


i having trouble returning static private variable personcount. variable counts amount of people add program, in constructor person set every time person entered, personcount incremented 1. have created getpersoncount method returns int value of personcount.

my problem when trying implement method in test file, unsure on how call method, , value of personcount logged output.

i'm not sure if million miles away or small syntax error away, appreciated!

my person constructor:

public person(string forename, string surname, int age,         double height, string gender) {     this.forename = forename;     this.surname = surname;     this.age = age;     this.height = height;     this.gender = gender;      personcount = personcount +1; }  

my getpersoncount method:

public int getpersoncount()         {             return personcount;         } 

my attempt call method in test drive:

    system.out.println(getpersoncount()); 

please let me know if more code needed.

try this, make method definition in class person like:

public static int getpersoncount() { //<-- note static modifier    return personcount; } 

to invoke it:

system.out.println(person.getpersoncount());//<-- use class name, if using method outside class 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -