Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Create a class that implements runnable with an example in Java

Create a class that implements runnable with an example - Java:


public class AddNumbers implements Runnable {
   /**
   * This method add two integers.
   * @param numberOne first param to add.
   * @param numberTwo second param to add.
   * @return int Obtains the sum of numberOne and numberTwo.
   */   
   public int addIntegers(int numberOne, int numberTwo) {
       //Variable to store the total sum
       int total = 0;
       //Sum the two numbers
       total = numberOne+ numberTwo;
       //Return the total
       return total;
   }

   /**
   * One Example
   */
   public static void main(String args[]) throws IOException {

      AddNumbers  addNumbers= new AddNumbers ();
      //Example
      int sum = addNumbers.addIntegers(10, 20);
      //Output
      System.out.println("Sum of 10 and 20 is :" + sum); //30
   }

   /**
   * This method is used to run the thread.
   */   
   public void run() {
      System.out.println("Thread is running");
   }
}
Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)