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.