Hello, in this video I am going to cover constants in classes. So a constant is local variable. But as the name suggests, its value cannot be changed it is constant and you need to declare a value when you you know, I mean you need to set a value when you initially declare the variable. Let's create a class called math. And we're going to create a constant in here, the keyword const, I'm gonna call it pi. So I'm just gonna, you know, have a constant for pipe to three decimal for me five decimal places.
And I'm also gonna have a control constructor. constructor. And in here, I am going to, because this is going to be triggered straightaway, I'm just going to echo out like so. And now I'm just going to create a object of this class. So, my OBJ equals new my warning so on identify constant pi dollar This is from the actual class itself on define property strange indeed, please come constants to the topic constants in a class during this room Sorry, my bad, it's always good to correct yourself. So, so, look, so there we go, it prints it out.
But watch what happens if I try and modify it. So if I do cell equals, let's say, new information comes out and it is 4.31. Now, we get an error, because it says unexpected can, you cannot, you know, change the value of a constant. So this is invalid, and it will throw an error and prevent the rest of the application from running. So that is how you do constants. In classes.
I just made a little mistake where I forgot how to access this using the self, not the this keyword. So, just make sure you don't make that mistake that I did. And as usual, thanks for watching, and I look forward to seeing you in the next video.