00:04This video is going to be about the celebratory word DISC.
00:09So what is DISC in Java?
00:14Well, the word DISC is a keyword that is used to refer to the current object of a method or a constructor.
00:28This way of saying it is like... it's the way of saying this or that.
00:37So, the word DISC is used to differentiate between class attributes and constructor parameters.
00:48So let's look at it with this example that we have here.
00:53In this case we have a product class called product with two attributes.
01:00A string called name and an integer called price.
01:06So here we can see that we have a parameterized constructor with two parameters also of type string and integer.
01:19With the same name as the attributes.
01:22So here we have the reserved word DISC.
01:27So what is this word for?
01:32Well, as you can see, if we had the constructor like this, how do we tell it that what we want to save in the name attribute is going to be the constructor parameter?
01:57Well, Java gets confused, so it doesn't know which of the two it is.
02:06So if you put the word DISC.name.
02:11Here we are indicating that we want whatever the name parameter contains to be assigned to the name attribute.
02:28The attribute, this is the one of the class.
02:35So what does DISC mean?
02:37Right here he is telling you this name.
02:43That is, when it says this name it refers to the attribute of the class.
02:49So, once, once already corrected.
02:58And as you can see, down here there is a method that doesn't return anything called show product.
03:06So here we can see that System.2.print is going to display the name on the console.
03:17But, it will show us the name of the parameter in case this method had a parameter equal to name.
03:32If this had been like this, it would show us and this would be here like this.
03:39What would this mean?
03:43It will not only show us the variables, it will show us the attributes of the class, but it will also show us the parameters of the method.
03:57So, I don't want to see the method parameters.
04:04I want to see the attributes of the class.
04:08So, I put the reserved word DISC.
04:15We do the same.
04:18And that's it.
04:20And this is what it would look like.
04:22Here we have another class of students.
04:25Which has two attributes.
04:27Name and age.
04:29With builder.
04:31We have two constructors in this case.
04:34One by default.
04:38And another parameterized with two parameters.
Sé la primera persona en añadir un comentario