0
0
Kotlinprogramming~10 mins

Calling Java from Kotlin seamlessly - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an instance of the Java class JavaClass in Kotlin.

Kotlin
val javaObj = [1]()
Drag options to blanks, or click blank then click option'
AJavaClass
BjavaClass
CJava_Class
Djava_class
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect class names.
Trying to use Kotlin-specific syntax for Java class instantiation.
2fill in blank
medium

Complete the code to call the Java method getGreeting() from the Kotlin object javaObj.

Kotlin
val message = javaObj.[1]()
Drag options to blanks, or click blank then click option'
Agetgreeting
BgetGreeting
Cget_greeting
DGetGreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Changing the case of the method name.
Using underscores instead of camelCase.
3fill in blank
hard

Fix the error in calling the Java static method JavaClass.staticMethod() from Kotlin.

Kotlin
val result = JavaClass.[1]()
Drag options to blanks, or click blank then click option'
Astatic_method
BStaticMethod
CstaticMethod
DStatic_Method
Attempts:
3 left
💡 Hint
Common Mistakes
Changing method name casing.
Trying to call static methods like instance methods.
4fill in blank
hard

Fill both blanks to create a Kotlin function that calls a Java method calculateSum(int a, int b) and returns the result.

Kotlin
fun sum(a: Int, b: Int): Int = javaObj.[1]([2], b)
Drag options to blanks, or click blank then click option'
AcalculateSum
Ba
Cb
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names.
Passing wrong variables as arguments.
5fill in blank
hard

Fill all three blanks to create a Kotlin property that calls a Java getter method getName() from javaObj.

Kotlin
val name: String
    get() = javaObj.[1]()

fun printName() {
    println([2])
    println(javaObj.[3]())
}
Drag options to blanks, or click blank then click option'
AgetName
Bname
Dgetname
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing for method names.
Printing the method call instead of the property.