Wednesday, November 11, 2015

Lession2 :: (Instance variables, Class variables, Local variables)

  • Any variable which is available inside a method is called as local variable.

Example ::

public class Display {
         public void getData(){
                   int a = 10; // Local Variable
         }
}


  • Any variable which is declared inside class and outside of a method is called as instance variable.
  • Any variable which starts with static keyword is called as class variables.

Example ::

public class Display {
       static int x = 10; // Class variable
       int y = 20; // Instance variable

       public void getData(){
             int  z = 30; // Local Variable
       }
}

No comments:

Post a Comment