hi guys, just i'm a beginner to kotlin progra, any...
# getting-started
r
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
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
i got your second point, but can you please explain bit about the contain state?
@marstran
m
By the way, please don't spam all channels with the same question. This channel is suited for these kinds of questions.
r
@marstran sure
m
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
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
Java interfaces cannot contain instance fields, only constants
r
thanks