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
Hungarian
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
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
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.