public class Main extends Thread {
//Variable declaration
private String message="";
private int delay=0;
//Constructor without parameters
public Main()
{
System.out.println("Main Class -> constructor");
}
//Constructor with parameters
public Main(String message, int delay)
{
this.message = message;
this.delay = delay;
//System.out.println("Running from myThreadClass --> Constructor!");
}
//Run function -> He is where we gonna manipulate our thread
public void run()
{
try {
int counter = 1;
for(int i=0; i < 10; i++)
{
System.out.println(message + " " + "with delay of" + " " + delay + " " + "counter" + " " + counter);
Thread.sleep(delay);
counter++;
//System.out.println("Hello -> Run Function");
}
}catch(Exception e)
{
System.out.println("Something went wrong -> Please try agian ");
}
}
//Main static function -> here is where our code will run -> all the functions will be called
public static void main(String[] args) {
Main t1 = new Main("Angola is the best country of the world", 200);
Main t2 = new Main("The flag is has 3 colors : Red, Black and Yellow", 400);
Main t3 = new Main("The president is JOAO MANUEL LOURENCO", 500);
t1.start();
t2.start();
t3.start();
// System.out.println("Working now!");
//System.out.println("Working");
}
}