java - Parameter scope vs local variable scope? -
i reading ap cs book , talked 3 types of variables:
•instance variables
•local variables
•parameters
instance variables visible throughout class etc... parameters usable within method , local variables . . .
therefore question why classify parameters , local variables different categories of variables if contain same scope. . . despite different uses of them.
because don't have same scope.
take case:
// garbage code public void dosomething(int foo) { int meh = 0; while (true) { // can access foo , meh int blah = meh++; if (blah == foo) { break; } } // won't compile, can't access blah anymore system.out.println(blah); // compile system.out.println(foo); // compile system.out.println(meh); }
Comments
Post a Comment