Exploring the MixedMethods Class By SFDC TELUGU

 

Exploring the MixedMethods Class

Let's dissect the MixedMethods class, which showcases different types of methods for arithmetic operations.

1. Class Declaration and Instance Variables

In this segment, we define a public Apex class MixedMethods with two instance variables num1 and num2. These variables will store integers on which we'll perform arithmetic operations.

2. Constructor to Initialize Variables

The constructor MixedMethods initializes num1 and num2 with values passed during object instantiation. This ensures our class is ready to perform operations with specific integer values.

3. Void Method for Addition (addAndPrint)

Here, addAndPrint is a void method, meaning it performs an operation (num1 + num2 in this case) without returning any value. It prints the result using System.debug(), which is useful for debugging and logging purposes.

4. Return Type Method for Subtraction (subscractNumbers)

subscractNumbers is a method that returns an Integer. It calculates the difference between num1 and num2 and returns the result, demonstrating how to define methods that return values in Apex.

5. Static Method for Multiplication (multiplyNumbers)

The static method multiplyNumbers showcases how to define methods that can be called without creating an instance of the class (MixedMethodss). It takes two integer parameters, multiplies them, and returns the result as an Integer.

6. Static Method for Division (divideNumbers)

divideNumbers is another static method that returns a Decimal. It performs division of n1 by n2, ensuring to handle the scenario where n2 might be zero to prevent division by zero errors. If n2 is zero, it returns null.

The MixedMethods class exemplifies the versatility of methods in Salesforce Apex:

  • Constructor: Initializes instance variables upon object creation.
  • Void Method: Performs an operation (addAndPrint) without returning a value.
  • Return Type Method: Computes and returns a result (subscractNumbers).
  • Static Methods: Demonstrates operations (multiplyNumbers and divideNumbers) that can be called without class instantiation.

By understanding and utilizing these concepts, developers can effectively encapsulate logic and streamline operations within their Apex applications.

Watch Video


Stay tuned for more insightful Apex tutorials and examples on our YouTube channel and blog!

  • Stay tuned for more tutorials and join our community SFDC Telugu! 

    Apex Programs PDF Free Downloads For Channel Members Join Channel Membership 

    For more detailed explanations, practical examples, and resources, refer your friends to SFDC Telugu:











  • www.sfdctelugu.in




  • Post a Comment

    0 Comments