‫Welcome back.
‫In Kotlin, the open keyword is used to declare a class, function, or property as open for extension.
‫When you mark a class function or property with the open keyword, it means that it can be subclassed
‫or inherited or overridden by other classes or functions in other parts of your code.
‫This is a way of explicitly allowing other parts of your code base to extend or customize the behavior
‫of the mark entity.
‫In our example, I used open with classes.
‫When you declare a class with the open keyword, it allows other classes to inherit from it.
‫This is used in the context of class inheritance.
‫Here, if we go back to the firing robot, we can see that there is no error.
‫I am inheriting from the general robot and I'm passing name as its value again for the super robot.
‫I remove this and I'll extend from General Robot and here passing the name also for the ordinary robot,
‫I need to extend from General robot class and remove the van.
‫From here.
‫Pass into the constructor of the general robot the name parameter.
‫So in this class I mark the general robot as open to allow firing robot, super robot and ordinary robot
‫to inherit from it and override walk and speak methods.
‫Let's go back to our Hello Kotlin file.
‫I'll remove this class because I moved it to the general robot.
‫Also, I need to create a new robots robot, basic robot or ordinary robot equals to ordinary robot.
‫Here I'm calling the constructor of this class and I need to pass the name of this ordinary robot.
‫I'll name it as Max.
‫If I type ordinary robot Dot, I can access the turn on light.
‫This is the function in this class and I want from you to focus.
‫Now if I need to access other functions, I can access the name attribute and the walk and the speak
‫functions here.
‫I didn't define any speak or walk function, but this class inherits from the general robot, and if
‫we go back to the general robot, we can see there are two functions walk and speak.
‫When you inherit from a superclass, you can access the superclass methods.
‫For example, the ordinary robot can access the walk method.
‫If I run the program now, you can see that the robot is walking.
‫Also, you can create another robots.
‫Super robot equals to super robot.
‫And here I need to pass body for example its name.
‫And here the super robot dot clean house.
‫I need to access this function.
‫Run the program and you can see the second robot is cleaning the house.
‫Also, you can create an instance from the firing robot equals to firing robot.
‫And here I need to name it as hero firing robot.
‫I can access walk, speak and fire method.
‫So every robot has its own skill, its own function fire, clean house, turn on light.
‫And among all robots we have two basic functions walk and speak.
‫I can access fire speak and a walk run.
‫The program and you can see it's firing.
‫So congratulations guys.
‫We learned about inheritance.
‫We'll learn about open keyword.
‫We learned how we call the super functions and how we organize our code to get rid of duplicate codes
‫from classes.