syntax:
abstract class Name{
abstract fun methodName()
}
===============
abstract class - It is uses an abstract keyword and a class keyword followed by the class name and optional class header. The body of an abstract class may contain one or more abstract methods. Once the class or the method is declared abstract, you don't need to specify it with an open keyword. Remember that the open keyword is used when you want to extend that class to another class.
================
import kotlin.math.PI
import kotlin.math.pow
fun main(){
val obj = MyCircle()
obj.calculateArea()
}
abstract class Circle(var radius: Double = 0.0){
abstract fun calculateArea()
}
class MyCircle: Circle(){
override fun calculateArea(){
radius = 3
val squaredRadius = radius.pow(2.0)
val answer = PI * squaredRadius
println("answer: $answer")
}
}
===================
Result:
answer: 28.274333882308138
Note: You can override a non-abstract open member with abstract member
YOU ARE READING
Kotlin Programming
RandomI have been trying to learn things online. I will put my notes in here. I put things in my own words and i do not copy their programs. I try to do things the right way so that i may learn. Below is the site where i study. Go check this out if you wa...
