# \[Java\] Using a subclass' function

**URL:** <https://forum.kirupa.com/t/java-using-a-subclass-function/270230>\
**Category:** programming\
**Created:** [September 7, 2008, 3:52am UTC](https://forum.kirupa.com/t/java-using-a-subclass-function/270230 "2008-09-07T03:52:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [September 7, 2008, 3:52am UTC](https://forum.kirupa.com/t/java-using-a-subclass-function/270230/1 "2008-09-07T03:52:01Z")

</div>

I have a superclass Shape and many subclasses: Sphere, Cube, Cylinder, etc… Each of these subclasses extends Shape with a function called printData().

```php

Shape[] shapes = new Shape[3];
shapes[0] = new Sphere();
shapes[1] = new Cube();
shapes[2] = new Cylinder();

shapes[0].printData();

```

I cannot figure out how to call printData(). The compiler seems to be looking into Shape.java for the printData() method, whearas it should have been looking in the subclass for it.

```auto

main.java:89: cannot find symbol
symbol : method printData()
location: class Shape

```
