Execute Java method in Gradle task

Having following Java classes:
public class Car {
public void ride(){
System.out.println(“riding…”);
}
}

public class Train {
public void signal(){
System.out.println("signalling...");
}
}

I would like to create two Gradle separate tasks, where first would execute ride() and second would execute signal() method.
Could you please advice, how to do it?

You can literally create the simplest tasks possible that do nothing other than instantiate the class and call the methods from a single file. Are there some other constraints to your question?

task ride {
    doLast {
        new Car().ride()
    }
}

task signal {
    doLast {
        new Train().signal()
    }
}

public class Car {
    public void ride() {
        System.out.println("riding…");
    }
}

public class Train {
    public void signal() {
        System.out.println("signalling...");
    }
}