5-8 LocalVar

posted Mar 29, 2014, 10:27 AM by Dlovan ismail
//Thls program demonstrates that two methods may have local variables with the same name.

package localvar;

public class LocalVar 
{
        public static void main(String[] args) 
        {
            texas();
            California();
        }

        // The texas method has a local variable named birds.

        public static void texas()
        {
            int birds = 5000;

            System.out.println("In texas there are " + birds + " birds.");

        }

        // The California method also has a local variable named birds.

        public static void California()
        {
            int birds = 3500;

            System.out.println("In California there are " + birds + " birds.");

        }
    
}

ċ
LocalVar.java
(1k)
Dlovan ismail,
Mar 29, 2014, 10:27 AM
Comments