It seems that there are two ways to define a sealed class, which one is corret between Code A and CodeB ?

**Code A**

```
sealed class ExprA
data class Const(val number: Double) : ExprA()
data class Sum(val e1: ExprA, val e2: ExprA) : ExprA()

```

**Code B**

```
sealed class ExprB{
    data class Const(val number: Double) : ExprB()
    data class Sum(val e1: ExprB, val e2: ExprB) : ExprB()
}

```
['https://Stackoverflow.com/questions/51296572', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/828896/']
<https://kotlinlang.org/docs/reference/sealed-classes.html>

> 
> To declare a sealed class, you put the sealed modifier before the name of the class. A sealed class can have subclasses, but all of them must be declared in the same file as the sealed class itself. (Before Kotlin 1.1, the rules were even more strict: classes had to be nested inside the declaration of the sealed class).
> 
> 
> 

If you're on < kotlin 1.1, then you MUST nest the classes in the sealed class; otherwise, you can declare them outside BUT those classes must be in the same file. Both are correct for kotlin >= 1.1
I can't say I've personally used the first way to write a sealed class so I'm not sure if that is syntactically correct. If it is, it would really be a preference of code style. From a maintenance perspective, I would personally prefer the second because it is easier to read and ensure what is encapsulated in that sealed class.