I have a very basic problem with an object.
I create the object in an if() statement in my main method. (there is an else, so it will always be created.)
The Object has a print() method, which works fine, but when I put the myobject.print() outside the if() clauses where it was created I get an error: “cannot find symbol”.
I guess I m making a dumb beginner mistake, but the myobject.print() inside the if() clauses will work fine, so my question is, what s happening to my object ? ( The main method does not do anything else in between..)
else default to 20, 10, and fill randomly 1/4
{
int a = 20;
int b = 10;
Table myTable = new Table(a,b);
myTable.randomfill(Math.round((a*b)/4)); //round in case defaults change later
System.out.println("Printing Table .... ");
myTable.print(); <-- here it works
}
//always print !!
System.out.println("Printing Table .... ");
myTable.print(); <-- won't work
myTable is scoped to else block only. It is not visible after else block completion. If you want to access it outside of else block, you may define myTable outside else block and assign object to it inside else block.