Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between open class and abstract class?

abstract class ServerMock(param: String) {
   protected var someVar = params + "123"

   fun justMyVar() = someVar
}

Usage example:

class BaseServer(param: String) : ServerMock(param) {
   val y = someVar
}

Can this class be marked as open and not abstract?

What is the difference between open and abstract class?

like image 536
shiran Avatar asked Dec 03 '22 17:12

shiran


1 Answers

abstract class cannot be instantiated and must be inherited, abstract classes are open for extending by default. open modifier on the class allows inheriting it. If the class has not open modifier it is considered final and cannot be inherited.

like image 65
Nikola Despotoski Avatar answered Dec 11 '22 15:12

Nikola Despotoski