Instantiate class from other script but same gameObject

I have two scripts in my Main Camera:

    public class defaultBehavior : MonoBehaviour {
    	void Start () {    
            messages msg = new messages();
	     	msg.isMsgEnabled = true;
	    	msg.showMessage("teste");
    	}
    	void Update () {
    	}
    }

and

public class messages : MonoBehaviour {
	
	public bool isMsgEnabled = false;
	
	public void showMessage(string message) {
		if(isMsgEnabled) {
			Debug.Log (message);
		}
	}
	
	
}

From defaultBehavior, how can I access my messages class, instantiate the isMsgEnabled bool and call the showMessage() void?

I’ve tried to instantiate with the new keyword but Unity throw me the following alert:

You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor()
messages:.ctor()

Try this link, expand Section 1 - Accessing methods and variables

Does the script need to inherit MonoBehaviour?

Try removing;

: MonoBehaviour

From the class declaration.

You can then access it via;

messages _messageClass = new messages();

The messages class should not inherit from MonoBehaviour if you want to instantiate it. Also, you should add a constructor to handle everything you want to happen when a new instance of the class is created. Like this:

using UnityEngine;

public class messages
{
	public bool isMsgEnabled;

	// Constructor
	public messages()
	{
            // Set isMsgEnabled to true
            // when a new instance is created
		isMsgEnabled = true;
	}

	public void showMessage(string message)
	{
		if (isMsgEnabled)
		{
			Debug.Log(message);
		}
	}

}

Next, your defaultBehavior script can be modified like so:

using UnityEngine;

public class defaultBehavior : MonoBehaviour
{
	messages msg;

	void Start()
	{
		messages msg = new messages();
		msg.showMessage("test");
	}
	void Update()
	{
	}
}