# Instantiation of a subtype of an abstract type

**URL:** <https://discourse.julialang.org/t/instantiation-of-a-subtype-of-an-abstract-type/58126>\
**Category:** General Usage\
**Created:** [March 28, 2021, 5:44pm UTC](https://discourse.julialang.org/t/instantiation-of-a-subtype-of-an-abstract-type/58126 "2021-03-28T17:44:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [March 28, 2021, 5:44pm UTC](https://discourse.julialang.org/t/instantiation-of-a-subtype-of-an-abstract-type/58126/1 "2021-03-28T17:44:54Z")

</div>

I’m following the MIT class “Introduction to Computational Thinking”, and have some trouble with the recent homework. (The class is _amazing_ by the way. Any applied math course should be taught in this way IMO.)

A structure is defined as follows.

```julia
struct RankOneMatrix{T} <: AbstractMatrix{T}
	v::AbstractVector{T}
	w::AbstractVector{T}
end

```

If we immediately construct an object using this type, we will get errors.  
We need to extend `Base.size()` and `Base.getindex()` first. Then the object of this type can be constructed.  
Is this the canonical way to inherit an abstract type like `AbstractMatrix`?  
Or there is a better way to do the same thing?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 28, 2021, 5:47pm UTC](https://discourse.julialang.org/t/instantiation-of-a-subtype-of-an-abstract-type/58126/2 "2021-03-28T17:47:24Z")

</div>

The reason you are getting an error is that when you create an object in the repl, Julia prints it out to show what you did. In order to print an `AbstractMatrix`, Julia needs to know how big it is, and how to get the elements.

---

<div class="post-metadata">

**Author:** ![linwaytin](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@linwaytin](https://discourse.julialang.org/u/linwaytin)\
**Post date:** [March 28, 2021, 6:16pm UTC](https://discourse.julialang.org/t/instantiation-of-a-subtype-of-an-abstract-type/58126/3 "2021-03-28T18:16:27Z")

</div>

Thanks, it makes sense now.

I just tested this in a script.  
No error shows up until I want to print the whole matrix.
