Friday, October 5, 2012

Execute Anonymous II:

Execute Anonymous II:
As continuous to previous execute anonymous post Execute Anonymous 1 ,we can test this example with an apex class.First create your class and observe the log using developer console by execute anonymous statements below

Dog myDogFido = new Dog();
myDogFido.play();
String myDogFidoStatus = myDogFido.getStatus();
System.debug('Fido is currently ' + myDogFidoStatus);



public class Dog {     // Declare a private String attribute called status     private String status;          // Declare a method to make the dog sit     public void sit(){         // Set the status to 'Sitting'         status = 'Sitting';     }          // Declare a method to make the dog play     public void play(){         // Set the status to 'Playing'         status = 'Playing';     }          // Declare a method to make the dog wag its tail     public void wagTail(){         // Set the status to 'Wagging Tail'         status = 'Wagging Tail';     }     // Declare a method that returns the status of the dog     public String getStatus(){         // Return the status attribute         return status;     } }

No comments:

Post a Comment