File tree Expand file tree Collapse file tree 3 files changed +103
-0
lines changed Expand file tree Collapse file tree 3 files changed +103
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Multithreading extends Thread {
2
+ public void run (){
3
+ try {
4
+ for (int i =0 ;i <5 ;i ++){
5
+ System .out .println (i );
6
+ Thread .sleep (1000 );
7
+ }
8
+ }
9
+ catch (InterruptedException e ){
10
+ e .printStackTrace ();
11
+ }
12
+ }
13
+
14
+ }
Original file line number Diff line number Diff line change
1
+ class Worker
2
+ {
3
+ String name ;
4
+ double salaryrate ;
5
+ Worker (String name , double salaryrate )
6
+ {
7
+ this .name =name ;
8
+ this .salaryrate =salaryrate ;
9
+ }
10
+ }
11
+ class Salariedworker extends Worker
12
+ {
13
+ int hours ;
14
+ Salariedworker (String name ,double salaryrate , int hours )
15
+ {
16
+ super (name , salaryrate );
17
+ this .hours =hours ;
18
+ }
19
+ double ComPay ()
20
+ {
21
+ double salary = 50 *salaryrate ;
22
+ return salary ;
23
+ }
24
+ }
25
+ class Dailyworker extends Worker
26
+ {
27
+ int days ;
28
+ Dailyworker (String name ,double salaryrate , int days )
29
+ {
30
+ super (name , salaryrate );
31
+ this .days =days ;
32
+ }
33
+ double ComPay ()
34
+ {
35
+ double salary = 50 *salaryrate ;
36
+ return salary ;
37
+ }
38
+ }
39
+
40
+ class Newsalary
41
+ {
42
+ public static void main (String args [])
43
+ {
44
+ Salariedworker sw = new Salariedworker ("Shayam" ,20.0 ,40 );
45
+ Dailyworker dw = new Dailyworker ("Ram" ,50.0 ,30 );
46
+ double sal = sw .ComPay ();
47
+ System .out .println ("SALARY OF SALARIED WORKER IS:" + sal );
48
+ double saly = dw .ComPay ();
49
+ System .out .println ("SALARY OF DAILY WORKER IS:" + saly );
50
+ }
51
+ }
52
+
Original file line number Diff line number Diff line change
1
+ class Thread implements Runnable {
2
+ Thread t ;
3
+ Thread M (){ //from here it will parallelly execute Thread M at same time
4
+ t =new Thread ("demo thread" );
5
+ System .out .println ("thread details" ,t );
6
+ t .start ();
7
+
8
+ }
9
+ public void run (){
10
+ try {
11
+ for (int i =0 ;i <5 ;i ++){
12
+ System .out .println ("child thread" ,t );
13
+ thread .sleep (500 );
14
+ }
15
+ }
16
+ catch (InterruptedException e ){
17
+ System .out .println (i );
18
+ }
19
+ }
20
+ }
21
+ public class multithread {
22
+ public static void main (String args []){
23
+ new Thread ();
24
+ try {
25
+ for (int i =5 ;i <1 ;i --){
26
+ System .out .println ("Main Thread" );
27
+ thread .sleep (1000 );
28
+ }
29
+ }
30
+ catch (Interpted Exception ){
31
+ System .out .println ("at end " + i );
32
+ }
33
+ }
34
+ }
35
+
36
+
37
+ //output will be 2 execution of first for loop and 1 execultion of second for loop
You can’t perform that action at this time.
0 commit comments