‫Welcome back.
‫In the last video, you saw the basics of abstract.
‫And I want to show you a little more about that.
‫So let's go ahead and and create a cube.
‫And it's going to it's going to be Ice Cube Baby.
‫And it's going to have a shape as a cube.
‫All right.
‫So this pretty much means that I want to create a cube, and it has to be the shape that we're currently
‫looking at as a cube.
‫So we're using this as a keyword in order to say I want to have it as a specific class type, whereas
‫a specific data type, the data type is cube, and that's the data type that we created ourselves.
‫It's like saying something as INT.
‫So I want to have this as an integer, but in this case we don't use a basic data type such as INT,
‫but we use a data type that we created ourselves.
‫So what I'm going to do now is I'm going to check if Ice Cube is not null, because if it is null,
‫then it's not a cube.
‫But if it's not null, then it will be a cube.
‫So this means if it is null, we can safely say this shape is no cube, all right, because it just
‫didn't work to add or put this into a cube.
‫Because well, if it's not in Cuba, then it will probably, in our case, be a sphere, right?
‫And then what I can also do is I can check if it is of a certain type, not just by using the double
‫equal sign and using null.
‫But I can actually check if the shape is of type cube.
‫And if that's the case, I can also safely say that this.
‫Is a cube.
‫Or this shape is a cube.
‫All right.
‫So we use the is keyword to check if a variable is of a certain type.
‫We use the as keyword in order to create a variable as a certain type.
‫It doesn't always work, though.
‫All right.
‫So now if we run this again, we will once see that this is a shape or the shape is is no cube.
‫And then we will see that this is a cube, because one of them is a cube, the other one is no cube.
‫So the first one is a sphere and it says the shape is no cube.
‫And the next one is this is a cube.
‫And it says the shape is a cube.
‫All right.
‫So now we can see that this actually worked, so we can actually check it.
‫And in this case, it's super stupid, right?
‫Because we're just checking it in order to write something onto the console.
‫But in other cases, it might actually be relevant for your program because then you can do something
‫with it.
‫If it is a cube, then you can do something particular, whether you can calculate it or you can adjust
‫it, or you can store it in a database or whatever.
‫If it's something else, then you would handle it differently.
‫Okay, so that's what you can do.
‫It's pretty cool.
‫It's part of polymorphism that we're using here.
‫That's pretty cool.
‫So you can see you have another functionality that you can use.
‫Now let's say we want to cast from an object to a cube.
‫This, of course, only works if the object, in fact, contains a cube.
‫All right, so let's create a cube.
‫I'm going to call this one cube one.
‫And it's going to be a new cube, and it's going to have a radius of seven.
‫All right.
‫So now what I can do is I can create a new cube, and I'm going to call this one cube two, which will
‫cast Cube.
‫One to a cube.
‫So what does that mean?
‫It means that I want to create a new cube called Cube two, and I want to cast Cube one into a cube.
‫This will, of course, only work if Cube one is, in fact, a cube.
‫And now we know that it is a cube.
‫But that's because we programmed it this way.
‫At the end, it's actually an object.
‫So it's an object which contains a cube.
‫So object is the class that is pretty much here supports all classes in the net class hierarchy and
‫provides low level services to derived classes.
‫This means that every single class is inheriting from this class called object every class.
‫And that's the case in C.
‫That's the case also in Java and other programming languages.
‫It's then probably any.
‫So for example, in Kotlin, it's a keyword any which is also the same kind of concept.
‫Right.
‫So this object class contains something like two string to hash and if you want to know more, you can
‫actually check it out.
‫So keep control key pressed and you can see it has equals reference equals gets hash code get typed
‫to string.
‫So these are the methods that every single object has, even though you haven't implemented it.
‫So you can very quickly see that by.
‫Using this for, let's say, our shape.
‫So here.
‫Shape start to string.
‫You can see it has this method same as shape dot equals get hashcode, get info and so forth.
‫So most of those properties that we can see here we haven't implemented, we just have them because
‫every class is inheriting from object.
‫All right.
‫So now.
‫Let's write something onto the console with our Q two that we have here.
‫So, C.W., and what I'm going to say is, has a volume of and then just going to pass or print the
‫volume.
‫So cube to name and cube to dot volume.
‫All right.
‫And this, of course, will only work.
‫If it actually is a cube, and in our case it is.
‫So it should work fine.
‫Now let's run it.
‫And we can see CUPE has a volume of 300 or 343.
‫So that's the cube that we created here, CUPE with seven.
‫All right.
‫So that's it.
‫Now, you have seen how to use abstract, how you can work with abstract classes, that when you create
‫an abstract class that you can of course, create abstract methods which you then have to implement
‫once a class inherits from this class.
‫So once a class inherits from shape.
‫All righty.
‫I hope you enjoyed this video.
‫This is another one of those videos where I got feedback.
‫People asked for it, so I decided to create this specific video.
‫And if you have any other demands or questions, please let me know in the question section or in discord.