+ 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
       // 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.