Inheritance in Kotlin & Any Class, What is Inheritance?

Kotlin supports single-parent class inheritance – so each class (except the root class Any) has got exactly one parent class, called a superclass. Kotlin wants you to think through your class design to make sure that it’s actually safe to subclass it, so classes are closed by default and can’t be inherited from unless you explicitly declare the class to be open or abstract. You can then subclass from that class by declaring a new class which mentions its parent class after a colon:

Inheritance is one of the key features of object-oriented programming. It allows user to create a new class (derived class) from an existing class (base class).

The derived class inherits all the features from the base class and can have additional features of its own.

The class declaration consists of the class name, the class header (specifying its type parameters, the primary constructor etc.) and the class body, surrounded by curly braces. Both the header and the body are optional; if the class has no body, curly braces can be omitted.

Suppose, in your application, you want three characters – a math teacher, a footballer and a businessman.

Since, all of the characters are persons, they can walk and talk. However, they also have some special skills. A math teacher can teach math, a footballer can play football and a businessman can run a business.

See Also  Budget School Management App

You can individually create three classes who can walk, talk and perform their special skill.

Kotlin supports single-parent class inheritance – so each class (except the root class Any) has got exactly one parent class, called a superclass. Kotlin wants you to think through your class design to make sure that it’s actually safe to subclass it, so classes are closed by default and can’t be inherited from unless you explicitly declare the class to be open or abstract. You can then subclass from that class by declaring a new class which mentions its parent class after a colon:

See Also  Learn Kotlin using Kotlin Koans & REPL(Read, Eval, Print, Loop)

Inheritance is one of the key features of object-oriented programming. It allows user to create a new class (derived class) from an existing class (base class).

The derived class inherits all the features from the base class and can have additional features of its own.

The class declaration consists of the class name, the class header (specifying its type parameters, the primary constructor etc.) and the class body, surrounded by curly braces. Both the header and the body are optional; if the class has no body, curly braces can be omitted.

Suppose, in your application, you want three characters – a math teacher, a footballer and a businessman.

Since, all of the characters are persons, they can walk and talk. However, they also have some special skills. A math teacher can teach math, a footballer can play football and a businessman can run a business.

See Also  Business directory listing app development

You can individually create three classes who can walk, talk and perform their special skill.

d93f3bce1660660e5de55f10d6df6f1a?s=96&d=mm&r=g
SyncSaShttps://syncsas.com
SyncSaS Technologies is specialized in creating and designing customized software. We have our own team that will be in charge of developing your softwares.

More from author

Related posts

Advertismentspot_img

Latest posts

How to increase YouTube Subscribers 2 Organic Strategy

How to increase YouTube Subscribers Being a YouTube personalities everyone wants the number of channel subscribers should multiply very quickly. Making YouTube video and uploading...

5 Ways to Increase Your YouTube Views

Increase Your YouTube Views Try going back and editing it to make it even better, and work on new videos. A helpful tip is to...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!