Please help with code
relativly new to java, and this is for a class so I am looking for documenation being pointed in the right way than direct answers.
I have a superclass with 2 subclasses.
I am trying to switch an object name between one of the two different object types so that as my program runs it will run based off the object type.
In short my code to switch between the object types is:
if (...)
{
SubClass1 x =new SubClass1();
}
elseif (...)
{
SubClass2 x =new SubClass2();
}
When I do this I get an error down the line the first time I try to use x.Method1(): error: "Cannot Find Symbol - variable x"
Can you not declare an object inside an if statement?
I am coding in BlueJ and that is required by my class.

