https://kotlinlang.org logo
Title
r

rajendhiraneasu

07/06/2017, 12:42 PM
hi guys, just i'm a beginner to kotlin progra, any one can explain what is the difference between abstract and interface in kotlin?
m

marstran

07/06/2017, 12:46 PM
rajendhiraneasu: Basically the same as in Java. An abstract class can contain state, but an interface cannot. Also, a class can implement any number of interfaces, but it can only extend one class.
r

rajendhiraneasu

07/06/2017, 12:47 PM
i got your second point, but can you please explain bit about the contain state?
@marstran
m

marstran

07/06/2017, 12:48 PM
By the way, please don't spam all channels with the same question. This channel is suited for these kinds of questions.
r

rajendhiraneasu

07/06/2017, 12:48 PM
@marstran sure
m

marstran

07/06/2017, 12:49 PM
You can define
val a = 5
in an abstract class. An interface can only define
val a: Int
. The class that implements the interface has to specify the value of
a
.
r

rajendhiraneasu

07/06/2017, 12:51 PM
but in java this abstract and interface contain this state right?
i.e. we can define and initialize the value in both abstract and interface right?
also in java interface does not have the method definition nah... but here in kotlin it works irght?
thanks for the help @marstran, sorry if i'm disturbing a lot
d

dagguh

07/06/2017, 1:14 PM
Java interfaces cannot contain instance fields, only constants
r

rajendhiraneasu

07/06/2017, 1:18 PM
thanks