All language subtitles for 011 Creating Class Instances_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
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
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

In the last section, we created a new class called the Person Class.

We're now going to use this class to create a new instance of it and then somehow call the print name

method assigned to that class to create a new instance out of this class.

We need to first define the main function.

Remember, any time darte runs, it's going to look for a function called main and execute that first.

So if we want to create a new instance of this class, we need to do it inside of that main function.

It's going to go up to the top of the file and give myself a little bit space and then I'll place the

main function, so right out void, main set of parentheses.

And this set of curly braces, by the way, we never really spoke about the void word right here.

Remember that any time we define a function to the left of the function name, we place a type that

indicates what type of value we are returning from this function.

And so before we had something like string over here, when we did that print name function previously,

if we have the word void right here, it means that we are returning nothing from this function at all.

So now that we have the main function put together, we can use this person class to create a new instance

of it.

So to create a new instance of a person of first declare a new variable, which I will say var and then

lowercase person.

So this right here is the variable declaration.

And then on the right hand side we will create a new instance of the class person by writing out new

person like so.

So that gives us a reference to a new person object that has been created inside of our application.

On the line underneath that, we can now attempt to set the first name property on the person instance,

so to access this first named property directly and set a new value on it, we can write out person

dot first name equals Steven, like sell or whatever your name might be.

Notice that we were able to set the value of first name right here as a string, specifically because

we labeled its type inside of the class definition.

If we had instead tried to assign an integer to this thing like one, two, three, we would end up

seeing an error message.

Well, we should anyways.

Let's try.

Sometimes you have to, like, kind of do a little bit of stuff to kind of get the thing to do.

Right.

Come on.

I know you think that's in there.

Let's try running this code.

There we go.

That's better.

So now, when I tried to assign an integer to the first name property, it's saying, hey, you can't

do that.

You're trying to assign an integer to a string.

All right, so I'm going to flip it back to Stephen like so.

So now that we have a defined first name property on our person object right here, we can call the

name method on it and I'll expect to see the name printed out on the top right inside.

So I'll do person dot print name like so.

And don't forget the semicolon on the end.

Now, if I run this code, I should see Stephen appear on the top.

Right.

And sure enough, I do.

OK, so this is a very quick example of how we work with classes, but I want to kind of point out something

inside of here.

Notice how creating this person object right here and then setting the first named property on it.

To do so, we had to write two separate lines of code.

Well, I don't know about you, but it sure seems like every person that we create inside of our application

is probably always going to want to have a first name.

In other words, how often do you meet a person in real life who doesn't have a name?

I think everybody has a name or most everyone does.

So I think that in the next section we should figure out some way of making sure that every person who

gets created inside this application always instantly gets a first name property assigned to them rather

than creating the person and then having to define that first name property on the next line.

So let's come back to the next section and we'll figure out how to do this all in one step right here.

It's a quick break and I'll see you in just a minute.

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