https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Doug

09/18/2020, 4:32 AM
In the following code, I’m trying to reuse a lot of the code from
ClassA
and only override a specific function in
ClassB
, is there anyway to do that, or do I need to ensure all of the methods require are created?
Copy code
interface View {
  fun loadFirstPage()
  fun otherFunction()
}
Copy code
open class ClassA: View {
  override fun loadFirstPage() { ... }
  override fun otherFunction() { ... }
}
Copy code
class ClassB: ClassA() {
  override fun loadFirstPage() { ... }
}
when I load
ClassB
, I’m only seeing the code from
ClassA
be executed
t

Tobias Berger

09/18/2020, 7:32 AM
does this compile? I would expect an error in ClassB because
loadFirstPage
is not marked as
open
in ClassA. Otherwise this should work just fine
3 Views