![]() In the AndroidPro class we are overriding the methodĪnd we are redefining the body of the function. Here, in the above example, the Parent class MindOrks is having a function namedĪnd this MindOrks class is inherited by the AndroidPro class. use the override keyword to override the function use open keyword to allow child class to override it Also, in the child class, you have to use the override modifier.įollowing is an example of a function overriding in Kotlin: you can’t override a function when the function isįunction Overriding is a process of redefining the functions of a Base class in a Child class. Just like classes, all the functions in Kotlin are by default Keyword otherwise you will get an error saying “ So, to make a class inheritable to the other classes, you must mark it with the This is opposite to what we learned in Java. So, MindOrks is the Parent class and AndroidPro is the Child class.īy default i.e. Here, in the above example, we are inheriting the class In Kotlin, to inherit one class from the other, you can use the below syntax: Here, MindOrks is the Parent class and AndroidPro, AndroidBeg, and DSAlgo are the Child class. So, instead of implementing these three methods separately in all the three classes, we can implement these methods in the MindOrks class and then use the methods by inheriting the MindOrks class. courseReg(), feePay(), and certificateGeneration(). Now, AndroidPro, AndroidBeg, and DSAlgo has three steps in common i.e. Now, think of the same situation in the Object-Oriented manner. For enrolling in any of the three courses, you have to first register yourself, then you have to pay for the course and after completion of the course, your certificate will be generated. So, these are different courses but they share something. ![]() As you know that MindOrks has various online courses like ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |