Page 156 - CTS - CSA TP - Volume 2
P. 156

COMPUTER SOFTWARE APPLICATION - CITS



           EXERCISE 102 : Create a thread by extending Thread class


            Objectives

           At the end of this exercise you shall be able to
           •  know the extension of threads in Java
           •  develop Java programs using  thread extension.


           Requirements

           Tools/Materials

           •  PC / laptop with windows OS
           •   SDK software
           •  Test editor (Visual studio/ subline/ notepad)



           Procedure


           Step 1: Define a class extending Thread





















              •  A new class named ThreadExtends is defined, and it extends the Thread class.

              •  The run method is overridden to define the behavior of the thread.
              •  Inside the run method, there is a for loop that prints a message with the current loop variable.
           Step 2: Create an instance and Start the Thread


























                                                           141
 CITS : IT & ITES - Computer Software Application - Exercise 101
   151   152   153   154   155   156   157   158   159   160   161