OOP IN JAVA - (TYPES OF VARIABLE | TYPES OF METHOD)

 Types of variables 


In Java mainly contain 3 types of variables.



LOCAL VARIABLE 

Variables are declared in a body way called local variables. You can use variables only in this method and not even other methods in the class.

ex - 


Instance Variable 


Variables declared inside a class but outside the body of a method are called instance variables. It is not declared as static. 
                                                                                               Is called an instance variable because its value is unique to an instance and is not shared between instances.

Points of the Instance Variable 



  1. To use an instance variable an object of the class must be created.
  2. An instance variable is destroyed when the object it is associated with is destroyed.
  3. An instance variable does not compulsory need to be initialized.
  4. Instance variables are accessible inside the same class that declares them.

Static Variable 

A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory.



TYPES OF  METHOD 

In java mainly 2 types methods contain 
        1. Predefined Method
        2. User Defined Method 

  1. Predefined Method
In Java, predefined methods are the method that is already defined in the Java class libraries is known as predefined methods. It is also known as the standard library method or built-in method. We can directly use these methods just by calling them in the program at any point.

                            Ex - psvm 


   2. User Defined Method 

The method written by the user or programmer is known as a user-defined method. These methods are modified according to the requirement.

                            Ex-  void eat {}


Thank You!


Comments

Popular posts from this blog

DEMYSTIFYING THE POWER OF x86 ARCHITECTURE

A GUID TO BEACOMING A SOFTWARE ENGINEER

JAVA LAMBDA EXPRESSION