0
0
Kotlinprogramming~10 mins

Class declaration syntax in Kotlin - Interactive Code Practice

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

Complete the code to declare a simple class named Person.

Kotlin
class [1]
Drag options to blanks, or click blank then click option'
APerson
BpersonClass
Cperson
DMyClass
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect class names.
Forgetting to capitalize the class name.
2fill in blank
medium

Complete the code to declare a class named Car with an empty body.

Kotlin
class Car [1]
Drag options to blanks, or click blank then click option'
A<>
B()
C[]
D{}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces for the class body.
Using square brackets or angle brackets.
3fill in blank
hard

Fix the error in the class declaration by completing the code.

Kotlin
class Person [1]
Drag options to blanks, or click blank then click option'
A<
B{
C(
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or angle brackets instead of braces.
Omitting the opening brace.
4fill in blank
hard

Fill both blanks to declare a class named Book with an empty body.

Kotlin
class [1] [2]
Drag options to blanks, or click blank then click option'
ABook
B()
C{}
DBook()
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces for the body.
Adding parentheses after the class name unnecessarily.
5fill in blank
hard

Fill all three blanks to declare a class named Animal with a primary constructor that takes a name parameter of type String.

Kotlin
class [1]([2]: [3]) {}
Drag options to blanks, or click blank then click option'
AAnimal
Bname
CString
Danimal
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase class name.
Swapping parameter name and type.
Omitting the type.