Why does this code only work if i invoke extends and create the subclass in main?
I originally defined the subclass "racecars" before the main, but it gave me an error (something about static/non-static variables--an aspect of Java that I don't fully comprehend yet) when I tried to create a new "racecar" in main. Here is the working code: public class Vehicle { protected String tires, color; public Vehicle() { tires = "four"; color = "blue"; } public static void main(String[] args){ class racecar extends Vehicle{ racecar(){ color="red"; } } Vehicle ford = new Vehicle(); racecar vw =new racecar(); } } Thanks in advance for your help, I'm supposed to be teaching Java in the fall so I need a firm grasp of all concepts.