function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bharath kumar 52bharath kumar 52 

difference between parameterized and non parameterized methods

Hi All,

Can someone tell me the difference between the 2 methods in the below and when should you go for parameters and non parameters(tjough they are used to achieve the same functionality)
 

public class WithandWithoutParams {
public integer a=2,b=3;
    public void meth1(){
        integer c= a+b;
        system.debug('Value without params >>>>>>'+c);
        
    }
    public void methwithparams(integer x,integer y){
        x=a;//overrides the value of this.a
        y=b;
        system.debug('x'+x+''+'y'+y);
        //y=this.y;
        //system.debug('xxxxx'+x);
      this.a=x;
        this.b=y;
        system.debug('a'+a+''+'b'+b);
        system.debug('x'+x+''+'y'+y);
       // x=this.x;
        integer z= x+y;
        system.debug('Value with params >>>>>>'+z);
        
    }
    
    
}
Suraj TripathiSuraj Tripathi

Hi Bharath,

In your given code the difference between parameterized and non parameterized methods are like:

Non parameterized meth1()

  • It is simply calculate the value.
  • also it used pre defined value.
Parameterized methwithparams(integer x,integer y)
  • In this method you are pass two values but it overrided by defined public values
  • x is assigning a
  • y is assigning b
hope it will help you.

Mark as a best if it helps you.

Regards,

Suraj