Sunday, 9 July 2017

Write an apex program to demonstrate usage of constructor?

Write an apex program to demonstrate usage of constructor? 

1) Open developers console by clicking the name on the salesforce page.
2) Click file & select apex class.
3) Enter the class name.
4) Write the apex class.

Ex:    public class employee 
         {
             String employee Name:
             Integer employee no:
             Public employee ()
            {
              Employee Name = ‘Hari’;
              Employee No = 10;
                    }
              Public void show ()
              {
                 System. Debug (‘employee Name is’ + employee Name);
                 System. Debug (‘employee No is’ + employee No);
                  }
               }

5) Open the anonymous block.

              Employee e1 = new employee ();
              Employee e2 = new employee ();
              E1. Show (); 
              E2. show (); 

This will give an output of employee Name is Hari and 

              Employee no is 10.
              Employee Name is Hari.
              Employee No 10.

No comments:

Post a Comment