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
shrayas reddyshrayas reddy 

I am getting a EOF error at 6th line in the code. I don't know how to resolve it

public class Myclass {
    void writeLog(){
        System.debug('hello world');
    }

}

Myclass c = new Myclass();
c.writeLog();
Best Answer chosen by shrayas reddy
ANUTEJANUTEJ (Salesforce Developers) 
Hi Shrayas,

You need to add access modifiers before void for the method to be visible, it can be private/global/public/protected.

To check more regarding access modifiers you can check this link:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm
private
This is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.
protected
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables. Note that it is strictly more permissive than the default (private) setting, just like Java.
public
This means the method or variable can be used by any Apex in this application or namespace.
=========================================================
Note
In Apex, the public access modifier is not the same as it is in Java. This was done to discourage joining applications, to keep the code for each application separate. In Apex, if you want to make something public like it is in Java, you need to use the global access modifier.
==========================================================
global
This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.

Please try the below code:
 
public class Myclass {
    public void writeLog(){
        System.debug('hello world');
    }

}

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.