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
ethan huntethan hunt 

Unexpected Token Public

Hi,,

 

Could you please help mw in the below code as it is throwing an 'Error: Compile Error: unexpected token: public at line 8 column 0'

 

public class test1
{
public integer text1{get;set;}
public integer text2{get;set;}
public integer text3{get;set;}
public integer text4{get;set;}
}
public decimal avg(int text1,int text2,int text3,int text4) ---------------------------------Errror line...
{
int result;
result = ((text1+text1+text1+text1)/4);
return result;
}

 

Regards

Puja_mfsiPuja_mfsi

Hi,

Please remove the end curly braces after the variable declaration.You need to declare all the variable and defining method inside one class .So after defining methods and variable you close braces of class.

 

public class test1
{
     public integer text1{get;set;}
     public integer text2{get;set;}
     public integer text3{get;set;}
     public integer text4{get;set;}

 

     public decimal avg(int text1,int text2,int text3,int text4) 
     {
              int result;
              result = ((text1+text1+text1+text1)/4);
              return result;
      }

}

 

Please give the kudos ( click on start at left),if this post is helpful.

Pathan S 4Pathan S 4
here showing errorr...Invalid type: int..plz check
Hanuma RudrarajuHanuma Rudraraju
Add the tag @AuraEnabled before the method
Suraj Tripathi 47Suraj Tripathi 47
Hi Ethan hunt,
Please remove the curly braces after "public integer text4{get;set;}" here you have close the class. You have to write everything in you class so put the curly braces at the end.
And for your second problem int is not supported in Apex you have to use Integer for taking integer value.

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

Thanks and Regards
Suraj Tripathi.