Codes For Practice:
Scenario 1: Calculator
public class Calculator {
integer a=10;
integer b=15;
public integer c; //without public we can-not access outside class
// but we can use inside of that class
public void addMethod(){
c=a+b;
system.debug(c);
}
public integer subMethod(){
return a-b; //direct return
}
public integer mulMethod(){
c=a*b;
return c; //first store and then return
}
public integer divMethod(){
c=a/b;
return c;
}
}
Anonymous window:
Calculator abc = New Calculator();
abc.addMethod(); //This add method's return type is void. That's why it can't be included in
System.debug() statement
system.debug('sub==>'+abc.subMethod()+
' mul==>'+abc.mulMethod()+
' div==>'+abc.divMethod());
Scenario 2: Sum of 1 to 100 number
public class SumNumbers {
integer i;
public integer sumAllNumber(){
integer sum =0;
for(i=1 ; i<=100 ; i++){
sum=sum+i;
}
system.debug(sum);
Scenario 1: Calculator
public class Calculator {
integer a=10;
integer b=15;
public integer c; //without public we can-not access outside class
// but we can use inside of that class
public void addMethod(){
c=a+b;
system.debug(c);
}
public integer subMethod(){
return a-b; //direct return
}
public integer mulMethod(){
c=a*b;
return c; //first store and then return
}
public integer divMethod(){
c=a/b;
return c;
}
}
Anonymous window:
Calculator abc = New Calculator();
abc.addMethod(); //This add method's return type is void. That's why it can't be included in
System.debug() statement
system.debug('sub==>'+abc.subMethod()+
' mul==>'+abc.mulMethod()+
' div==>'+abc.divMethod());
Scenario 2: Sum of 1 to 100 number
public class SumNumbers {
integer i;
public integer sumAllNumber(){
integer sum =0;
for(i=1 ; i<=100 ; i++){
sum=sum+i;
}
system.debug(sum);