October 2018
Intermediate to advanced
370 pages
9h 15m
English
In this section, we will see how to call the Kotlin class in Java. Create a Shape class in Kotlin with three properties, height, width, and area, and two functions, shapeMessage and draw:
class Shape(var width : Int, var height : Int , val shape: String) { var area : Int = 0 fun shapeMessage(){ println("Hi i am $shape, how are you doing") } fun draw() { println("$shape is drawn") } fun calculateArea(): Int { area = width * height return area }}
We can create an instance of the Kotlin class in the same way as we create an instance of a normal Java class. See the following example:
class FromKotlinClass { public void callShpaeInstance() { Shape shape = new Shape(5,5,"Square"); shape.shapeMessage(); shape.setHeight( ...
Read now
Unlock full access