# Subclass exposes its internal supertype

**URL:** <https://discuss.kotlinlang.org/t/subclass-exposes-its-internal-supertype/17105>\
**Category:** Language Design\
**Created:** [April 14, 2020, 1:46am UTC](https://discuss.kotlinlang.org/t/subclass-exposes-its-internal-supertype/17105 "2020-04-14T01:46:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Void](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Void](https://discuss.kotlinlang.org/u/Void)\
**Post date:** [April 14, 2020, 1:46am UTC](https://discuss.kotlinlang.org/t/subclass-exposes-its-internal-supertype/17105/1 "2020-04-14T01:46:31Z")

</div>

Inheritance chain like this is not allowed:  
`Public class` \> `Internal implementation` \> `Public interface`.

And gives compile time error: `Subclass exposes its internal supertype`.

I just wonder how exactly it exposes? Internal implementation doesn’t have any new public methods, just those which are already exposed, so what exactly is exposed?

```auto
class Public : InternalImpl<Int>() {
    override fun publicFun() {
        super.publicFun()
    }
}

internal open class InternalImpl<T> : PublicInterface<T> {
    
    private fun privateFun() {

    }

    override fun publicFun() {

    }
}

interface PublicInterface<T> {
    fun publicFun()
}

```

---

<div class="post-metadata">

**Author:** ![tieskedh](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tieskedh/32/2816_2.png) [@tieskedh](https://discuss.kotlinlang.org/u/tieskedh)\
**Post date:** [April 20, 2020, 11:09am UTC](https://discuss.kotlinlang.org/t/subclass-exposes-its-internal-supertype/17105/2 "2020-04-20T11:09:33Z")

</div>

```
class Public : PublicInterface<T> by InternalImpl<Int>()

```

I believe the answer to the problem itself is given here:

> [@Why does Kotlin prohibit exposing restricted-visibility types?](https://discuss.kotlinlang.org/t/why-does-kotlin-prohibit-exposing-restricted-visibility-types/7047/6):
>
> The reason is this. Kotlin’s default visibility is public, and the goal is that you don’t have to pollute your internal and private classes with explicit visibility modifier. Declaring your class as private or internal should be enough to hide it from the outside world. Now, if this class happens to be open and you inherit from it a public class, then you accidentally leak details that were originally supposed to be private/internal to the outside world. This is error-prone (hard to notice) and …
