use methods of one class in another

Asked

Viewed 28 times

-1

I’m making a simple application, and when it comes to using the methods of one class in another, it’s not working.

I have the following class:

    import org.bson.Document;
    import com.github.fakemongo.Fongo;
    import com.mongodb.client.FindIterable;
    import com.mongodb.client.MongoCollection;
    import com.mongodb.client.MongoDatabase;

    public class Model {
        Fongo fongo = new Fongo("mongo");


        public void addEmpresario(Document user) {
            MongoDatabase db = fongo.getDatabase("antenas");
            MongoCollection<Document> empresario = db.getCollection("empresario");
            empresario.insertOne(user);
        }
   }

And the main, which for now has nothing. How do I call this class in the main?

  • only you instantiate the class in the main Model model = new Model(), and so you use some class method you use model.addEmpresario(parameters)

1 answer

0

Go to your Main() class and enter the Model class. Ex:

main(){
   Model model = new Model()
   model.addEmpresario(parametro)
}

don’t forget to import your class location at the beginning of the main file

Browser other questions tagged

You are not signed in. Login or sign up in order to post.