Java variables

 

Quiz : https://take.quiz-maker.com/QZHMSPRBI

Java Variables

  • Variables are the container which hold the value, value can me change depend on condition.
  • A variable assigned with a data type.
  • Variable is a name of memory location. 

  • Types:
  1. Local
  2. static
  3. instance
  • Local variable:
  1. A variable declared inside the body of the method is called local variable.
  2. Access modifiers cannot be used for local variables.
  3. A local variable cannot be defined with "static" keyword.
  • Instance variable:
  1. A variable declared inside the class but outside the body of the method.
  2. A Instance variable cannot be defined with "static" keyword.
  • Static variable:
  1. A variable that is declared as static is called a static variable.
  2. Static variable can be use for a entire program.
  3. It cannot be local.
  4. Memory will be allocated to the static variable at the time of class loading.
  • Example:
Public class Abhinav{

                 static int Ram=100;//static variable

                 void manvik(){

                               // method body
                              int n=90;//local variable

                             }
               public static void main(String args[]){

                             int age = 21;//instance variable
          }
}

YouTube channel Link : https://www.youtube.com/@rowcoder 











Comments