Long story short, I cannot figure out why this code doesn't work.
import java.util.*;
class sup{
int a;
sup(){
a = 1;
}
}
class subB extends sup{
int b;
subB(){
b = 2;
}
}
class subC extends sup{
int c;
subC(){
c = 3;
}
}
public class runMain{
public static void main(String args[]){
List<Object> classes = new ArrayList<Object>();
classes.add(new sup());
classes.add(new subB());
classes.add(new subC());
System.out.println(classes.get(0).a); //should print 1
System.out.println(classes.get(1).b); //should print 2
System.out.println(classes.get(2).c); //should print 3
}
}
As stated in the comment, I am wanting the last 3 lines to print the values of a, b and c in the different classes. When instead having e.g.
System.out.println(classes.get(0));
it prints sup@6d06d69c
, which I assume is just the class name "@" the memory location, so everything else in the program seems to be working as intended.