What is the difference between sealed abstract
and abstract
Scala class?
1)Sealed class cannot be inherited by a normal class. 1)Abstract class must be inherited by a class. 2)Instance must be used for Sealed class for accessing its public methods. 2)Instance cannot be created for Abstract class and it should be inherited for accessing its abstract methods.
When a class is declared sealed, it cannot be inherited, abstract classes cannot be declared sealed.
Abstract Class supports single inheritance only. Trait can be added to an object instance. Abstract class cannot be added to an object instance. Trait cannot have parameters in its constructors.
static class cannot be marked sealed because it is made sealed by compiler by default. Static classes are sealed and therefore cannot be inherited. static class cannot be marked as abstract , because it would be pointless. abstract class makes sense when you want all derived classes to implement same part of the logic.
The difference is that all subclasses of a sealed class (whether it's abstract or not) must be in the same file as the sealed class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With