Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Static variables belong to a class.
Fields belong to an object, but static variables belong to the class.
In this lesson, you're going to learn about static variables.
First things first in your Java Bootcamp resources, open up the folder for this lesson by following
this path.
All right, a static variable, as we just said, belongs to the class, a static variable does not
belong to an object.
The employee class models to fields and has one static variable.
Each employee object that we create from the employee class has different values for name and position.
But the number of employees hired to relate to the class, not objects of the class.
Inside main Java create three objects of the employee class.
I'll create an employee called Zack, new employee.
We'll make him a programmer.
Or create another one named Geo.
Analyst.
And let's say Thomas.
Specialist.
All right, your task is to count how many employees were hired, the number of employees hired relates
to the class, not objects of the class.
So inside employee class create a static integer variable called hired count.
Every time we create a new object of the employee class, we're going to update hired count by one.
And because a static variable belongs to the class, you can access it directly from the class type.
We're going to print the number of employees we hired employee hired count.
Run the code.
And the number of employees hired is three.
The output is more interesting with breakpoints, I'm out of Breakpoint next to each object launched
the debugger.
I'll step into the constructor for the first object.
The constructor updates every field in the object.
And it updates the static variable.
Notice that the static variable is not a member of the object the Zach object defines to Field's name
and position, the static variable belongs to the class.
And right now, it equals one.
I'll step into the constructor for the constructor, updates every field in the object.
And it updates the static variable to two.
The Jobs Act defines Namen position, but the static variable which belongs to the class now equals
to.
I'll step into the constructor for Thomas.
The constructor updates every field.
And it updates the static variable to three.
Each object defines a unique name and position.
But hired count is a member of the employee class, and that equals three.
Let's recap, a static variable belongs to the class, in other words, a static variable relates to
the class, not objects of the class.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.