Method

 Methods: 

Block of code which only runs  when  it is called.they are reusalble.


create a Method;

declare with in the class

returnType functionName(){

return  returnDataType ;

}


ex:2

accessModifier static returnType fucntionName(parameter){

}

public double getTenPercentOffDiscountPrice(int price){

return price*0.9;

}

accessModifier- public, private

static- methos belongs to class


Call method in java- functionName(parameter);



informations can be passed to methods via parameters,paramente acts as vaibales inside methods,method will have unlimited amount of parameters , recommends only 3 


Parameters verus Argumenets:

Parameter passed to method is called argument. price-parameter

public double getTenPercentOffDiscountPrice(int price){

return price*0.9;

}

getTenPercentOffDiscountPrice(20000);20000 is argument.



Method Overloading :multiply methods will have samename with diff parameters.

returnType sameFunctionName(dataType1 parameterName1){

---}

returnType sameFunctionName(dataType2 parameterName2){

---}

Example:

public double getTenPercentOffDiscountPrice(int price){

return price*0.9;

}


public double getTenPercentOffDiscountPrice(double price){

return price*0.9;

}

getTenPercentOffDiscountPrice(1000);

getTenPercentOffDiscountPrice(345.333);




Comments

Popular posts from this blog

Implicit and Explicit Waits,FluentWait,PageLoadTimeOut

A Interview Questions- selenium