‫Welcome back.
‫In this video, I want from you to focus with me because I'm going to talk about abstract in Kotlin.
‫In Kotlin, the abstract keyword is used to declare abstract classes and abstract functions.
‫Abstract classes are classes that can't be instantiated on their own and are typically meant to be subclassed.
‫Abstract functions are functions declared in an abstract class that don't have an implementation in
‫the abstract class, but must be implemented in subclass.
‫Let me show you here.
‫This general robot is marked as open so I can go to the hello Kotlin KTX file and I can create a new
‫variable called General Robot equals to General Robot.
‫And here I can pass the name General Robot.
‫So I can create instances of general Robot.
‫But if we go back and mark this class as an abstract abstract classes cannot be instantiated directly.
‫So you can't create an instance of general robot.
‫Instead, you are expected to create subclasses that provide concrete implementations for abstract functions.
‫This general robot needs to be replaced by either a super robot or ordinary robot, or a firing robot.
‫Instead, you can see that I can specify the type of general robot as general robot, but I'm creating
‫and using the constructor of the firing robot, which is a subclass of the general robot, and this
‫is called the polymorphism.
‫Since the firing robot, super robot, and ordinary robot are subclasses of the general robot, and
‫the general robot is marked as an abstract class.
‫So I can create instances of firing robot, super robot, and ordinary robot, and their type can be
‫marked as General Robot.
‫Back to our general robot class, I'll create a function marked as Abstract Fun and I'll name it as
‫start.
‫This function has no implementation in the general robot, so if I try to write a method body, there
‫is an error.
‫So I need to remove the body.
‫There is no implementation.
‫This function is required to be implemented in any concrete subclass of general robot.
‫So back to our subclasses.
‫You can see there are errors telling us that we need to override the start function alt plus enter to
‫implement the members, and here I need to implement the member.
‫Start back to our class.
‫You can see firing robot is implementing the start function and overriding the start function that it
‫is in the general robot class.
‫Here I'll override this function and create my custom println.
‫Message firing robot is started also with the super robot.
‫I need to override it so alt plus enter or you create.
‫You can create this red bulb, implement the members start click okay and the override function start
‫is implemented.
‫I need to print ln that this ordinary robot is started.
‫Again in the Super robot, I'll implement the members.
‫Click okay and here println.
‫Super robot is created.
‫You can see all the errors are solved because when you declare a function as an abstract, all the subclasses
‫must implement this function.
‫So back to hello Kotlin file.
‫I have an error walk.
‫I marked it as a protected.
‫Then here this general robot.
‫It's of type firing.
‫I can use this general robot instance dot start function.
‫Let me run.
‫And here we go.
‫A new robot is created.
‫Changing the model year and firing robot is started.
‫So I am calling this function and executing the println.
‫Firing robot is started.
‫Method will be shown.
‫This is the abstract keyword.
‫In Kotlin we have two things we can mark them as abstract.
‫Abstract class cannot be instantiated by their own.
‫They are typically meant to be subclassed and abstract functions don't have an implementation in the
‫abstract class, but must be implemented in the subclasses.