All language subtitles for 024 static Methods_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Static methods belong to the class.

Methods belong to the object, but static methods belong directly to the class.

In this lesson, you will learn to create static methods.

First thing's first hired count needs to be private.

The only place that needs to update hired count is the constructor.

The caller shouldn't be allowed to update it from Maine.

This is a security risk.

So make it private.

Now, a normal method belongs to an object because methods belong to an object, you can only call them

from the object like geotag get name.

Now create a method named get hired, counts public and get hired counts and it will return the number

of employees we hired.

Do you see what's wrong with the code, the static variable belongs to the class, it does not belong

to a particular object.

But in order to call get hired count, you need to create an object of the employee class.

In this case, I would have to create a new object of the employee class passing some random values

for the purpose of calling get hired counts.

All right, with that being said, accessing a static variable from an object doesn't make any sense.

You should be able to call this method directly from the class.

A static method belongs to the class.

So you can call it directly from the class.

Inside the employee class make the method static.

And now we can call the method directly from the class.

Java is even telling us to call it from the class.

Employees don't get hired counts.

And perfect.

We're able to access the static variable directly from the class.

It's also private, which means we don't have to worry about accidental updates inside men.

That being said, a static method can only access static variables, I'm going to repeat this one more

time.

A static method can only access static variables.

This begs the question, why can't a static method access fields paused the video and think about it.

The answer is a static method belongs to a class and fields belong to an object.

It's as simple as that.

Let's say you tried to access this name from a static method.

For clarity, I'm just going to use that this keyword.

It's the same thing, but anyways, this points to the current object that's calling this method.

So there's no object for this to point to, which is why job is going to tell you you cannot access

in objects fields from a static context.

Also, a static method can only access other static methods, take some time to really internalize the

following two sentences.

OK, why can't a static method access normal methods, pause the video and think about it?

The answer is simple a static method belongs to a class and a normal method belongs to an object.

Let's say you tried to access this thought, get name from a static method.

This points to the current object calling get name, but you're not calling get hired count from an

object, you're calling it from a class.

So there is no object for this to point to.

Job is going to tell you you can't access normal methods from a static context.

It doesn't make any sense.

So you understand these rules and you should be fine, a static method can only access static variables

and it can only access other static methods.

Here's a question for you.

Why does everything in Maine have to be static?

It doesn't make any sense to create an object of the main class.

For example, the main method is the entry point of your application, the compiler wants to call the

main method, but it doesn't want to have to create an object of the main class to do so.

It just wants to call it from a static context for simplicity.

It just wants to say mean that mean.

All right, why do class variables in Maine need to be static?

Remember, the first part of our rule, a static method can only access static variables.

If I want to use scanner inside mean it needs to be static as well.

If I remove the static key word, it's not going to work.

Why do other methods and may need to be static, remember the second part of our role, a static method,

can only access other static methods.

I'm going to create a random void method in Maine, public void, do stuff.

I'll try to call it from the main method, and it's not going to work.

If I want to call this method for Maine, it needs to be static as well.

Let's recap in this lesson, you learn to create static methods.

Static methods belong to the class, so you can call them directly from the class type.

And there are two things you should know about static methods a static method can only access static

variables and a static method can only access other static methods.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.