Skip to content

Commit 616fa0b

Browse files
authored
Add files via upload
1 parent 9514c2c commit 616fa0b

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

Multithreading.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

Newsalary.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+

multithread.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

0 commit comments

Comments
 (0)