Class Variables

Class Variables:-

               The variables in the class should specify the following properties when they are defined.

  1. Optional: Modifiers such as public or final as well as static.
  2. Required: The data type of the variable, such as string or boolean.
  3. Optional: The values of the variable.
  4. Optional: The name of the variable.
Syntax:
       [public/private/protected/global/final] [static] data_type Variable_name

Ex:
       Private Static final Integer My_int;
       Private final Integer i=1;



Class Methods:-

       To define a method, specify the following.
1.Optional: Modifiers, such as public or protected.
2.Required: The data type of the values returned by the method such as string or Integer.
                      Use Void if the method does not return a value.
3.Required: A list of input parameters for the method, separated by commas, each preceded by its                         data type, and enclosed in parameters(). If there are no parameters , use a set of empty                          parameters.A method can only have 32  input parameters.
4.Required: The body of the method, enclosed in braces{ }. All the code for the method, including any local variable declarations, is contained here.


Syntax:  
      (Public/Private/Protected/global) [override] [static] data_type method_name(input parameters)
     {
           
           // The body of the method;
               }

Ex: Public static Integer getInt()
        {
               return My_Int;
                    }


EX:   Public class Example
           {
           
             Public Integer Show(Integer age)
                {
                   system.debug( 'Myage is'  +age);
                            }
                     }



No comments:

Post a Comment