- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extend and implement at the same time in Kotlin?n
In this article, we will take an example to demonstrate how we can extend and implement in the same class. In this example,
We will be creating an interface and a dummy Parent class.
From the Child class, we will extend the Parent class and implement the interface.
Example – Extending and implementing in child
interface myInterface { fun test(): String } open class myParentClass(val name:String) { fun anotherTest():String { return name } } class Child() : myInterface, myParentClass("ParentClass Input"){ //child extending the parent class and implementing myInterface override fun test(): String { return "This is implemented interface: myInterface" } } fun main(args : Array<String>) { println(Child().test()) println("Reply from parent entity: "+myParentClass("hello parent").anotherTest()) }
Output
Once you execute the code, it will produce the following output −
This is implemented interface: myInterface Reply from parent entity: hello parent
- Related Articles
- How to extend and implement at the same time in Kotlin?
- How to catch many exceptions at the same time in Kotlin?
- Extend data class in Kotlin
- How to show multiple Canvases at the same time in Tkinter?
- How can one believe in science and religion at the same time?
- Implement Runnable vs Extend Thread in Java
- How to implement Builder pattern in Kotlin?
- How to select at the same time from two Tkinter Listbox?
- How to start a Service at Boot Time in Android App using Kotlin?
- How to get the current local date and time in Kotlin?
- How to identify multiple elements at the same time in Selenium with python?
- How to fetch only N rows at a time in MySQL?
- How to implement AlarmManager in Android using Kotlin?
- How to implement switch-case statement in Kotlin?
- How to find the groupwise mean and groupwise sum at the same time in an R data frame?
- Can an object be at rest and in motion at the same time? Give example.

Advertisements