- #1
zak100
- 462
- 11
Hi,
I am trying to create an array of 20 threads to perform addition of 20 elements of two arrays. I have created an inner class. I don't know if my inner class syntax is correct or not. My code is:public class Question{
static int [ ] input1 = new int[20];
static int [ ] input2 = new int[20];
static int[ ] output= new int[20];
class job extends Thread{
private int index;
job(int i) {
index=i;
}
public void run() {
output[index] = input1[index] + input2[index];
}
}
public static void main(String[ ] args) {
//initialize input arrays
int i=0;
for( i=0; i<20; ++i)
input1= i;
for( i=0; i<20; ++i)
input2= 1;
job[ ] t = new job[20];
for(i=0; i<20;++i){
job = new job(i);
t.start();
t.join();
}
for(i=0; i<20; ++i)
System.out.println(" " + output);
}
}I am getting following error in my code: job = new job(i);
^
symbol: variable job
location: class Question
Question.java:26: error: non-static variable this cannot be referenced from a st
atic context
job = new job(i);
^
2 errorsSomebody please guide me.Zulfi.
I am trying to create an array of 20 threads to perform addition of 20 elements of two arrays. I have created an inner class. I don't know if my inner class syntax is correct or not. My code is:public class Question{
static int [ ] input1 = new int[20];
static int [ ] input2 = new int[20];
static int[ ] output= new int[20];
class job extends Thread{
private int index;
job(int i) {
index=i;
}
public void run() {
output[index] = input1[index] + input2[index];
}
}
public static void main(String[ ] args) {
//initialize input arrays
int i=0;
for( i=0; i<20; ++i)
input1= i;
for( i=0; i<20; ++i)
input2= 1;
job[ ] t = new job[20];
for(i=0; i<20;++i){
job = new job(i);
t.start();
t.join();
}
for(i=0; i<20; ++i)
System.out.println(" " + output);
}
}I am getting following error in my code: job = new job(i);
^
symbol: variable job
location: class Question
Question.java:26: error: non-static variable this cannot be referenced from a st
atic context
job = new job(i);
^
2 errorsSomebody please guide me.Zulfi.