Inheritance java

Hey guys is there a way to declare a type of an object to the super class and then initialize it to the sub class and then use that object on a method that is only in the sub class?

getMedian() // only in subclass IntListSorted but I cannot use it this way

package project10;

public class Checkpoint1
{
public static void main(String args[])
{
IntList list = new IntListSorted();
list.add(5);
list.add(4);
list.add(1);
for(int j =0;j<list.size();j++)
{
System.out.println(list.get(j));
}
System.out.println(list.getMedian());
}

}

I'll take a closer look when I get home, but in general you'd use a constructor for initializing variables. So create a constructor in your subclass that sets the superclass' variable.

I found a solution I needed to down cast the list object in order to use methods that are not in the super class.

I beleive you want to use the (super) i.e the super key word.

the getMedian method isnt in the super class though.

you will declare a clas svariable that is the data structure from the supe rclass with the (super)

something along those lines, been a while.