# Supertype method call inside subtype method with same name

**URL:** <https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720>\
**Category:** New to Julia\
**Tags:** inheritance\
**Created:** [April 6, 2021, 10:30pm UTC](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720 "2021-04-06T22:30:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunny](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Post date:** [April 6, 2021, 10:30pm UTC](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720/1 "2021-04-06T22:30:49Z")

</div>

I defined some `struct` that is the subtype of `Parent`.  
There is a method I’d like to change for the `Child` type but at the same time I want it to call  
the same method for Parent type.  
What is the correct way to get this behaviour?

```julia
abstract type Parent end

mutable struct Child <: Parent
    height
end

get_height(x::Parent) = x.height/100
function get_height(x::Child)
    get_height(convert(Parent,x)) + 0.01
end

a = Child(180)
get_height(a) # should return 1.81

```

When I launch this code I get the following error:

```julia
StackOverflowError:

Stacktrace:
 [1] get_height(::Child) at ./In[18]:9 (repeats 79984 times)

```

I don’t want to change the name of my method, because there are many Children subtypes with similar methods

---

<div class="post-metadata">

**Author:** ![lhnguyen-vn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lhnguyen-vn/32/15449_2.png) [@lhnguyen-vn](https://discourse.julialang.org/u/lhnguyen-vn)\
**Post date:** [April 6, 2021, 10:42pm UTC](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720/2 "2021-04-06T22:42:31Z")

</div>

`Child` is already a subtype of `Parent`, so your `convert` call doesn’t change anything. Furthermore, `Parent` is an abstract type and so cannot be instantiated, i.e. no values can directly have type `Parent`, though they can be of its concrete subtypes.

You can use `invoke` to call the more generic method. Alternatively, you can also lean further into multiple dispatch:

```julia
_get_height(x::Parent) = x.height / 100

get_height(x::Parent) = _get_height(x)

get_height(x::Child) = _get_height(x) + 0.01

```

---

<div class="post-metadata">

**Author:** ![Sunny](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Post date:** [April 7, 2021, 8:33am UTC](https://discourse.julialang.org/t/supertype-method-call-inside-subtype-method-with-same-name/58720/3 "2021-04-07T08:33:39Z")

</div>

Interesting, thanks
