https://kotlinlang.org logo
#announcements
Title
# announcements
a

Ashutosh Panda

12/10/2019, 7:48 AM
Copy code
class book(){
    var pages:Int=300
}
class puppy(b: book)
{
    fun removePages():Int=b.pages-Random().nextInt(0,100)
}

fun book.getWeight():Double=pages*1.5
val hamlet=book()
val puppy=puppy(hamlet)
fun book.CountPages(i:Int):Int=pages-i
println("${hamlet.CountPages(20) } \n")
println("${hamlet.getWeight()} \n")
println("${puppy.removePages()+hamlet.CountPages(20)}")
i

Ivan Kubyshkin [JetBrains]

12/10/2019, 7:50 AM
Copy code
class puppy(val b: book)
m

Matthieu Esnault

12/10/2019, 7:51 AM
b
is provided to the constructor, but it’s not a property of the class
puppy
. try
Copy code
class puppy(val b: book)
Edit : too slow :)
👍 2
a

Ashutosh Panda

12/10/2019, 8:19 AM
Thanks
Still it's showing an error
Can't create an instance of abstract class
This is the error
i

Ivan Kubyshkin [JetBrains]

12/10/2019, 8:48 AM
Copy code
Random.nextInt(0,100)