If the constructor has a void in front of it, the java compiler doesnt recognize the
constructor at all. Here is the example (with ==> pointer where defn) and output:
// Destroying a thread.
import java.io.PipedOutputStream;
import java.io.PipedInputStream;
class speaker extends Thread {
private int speakerNumber;
==> public void speaker(int i, PipedOutputStream b, PipedInputStream c) {
speakerNumber = i;
}
public void run() {
int i = 0;
if (speakerNumber == 1)
stop();
while(++i < speakerNumber)
System.out.println("Hello World #" + speakerNumber);
}
}
class demo {
public static void main(String args[]) {
speaker speaker1, speaker2;
PipedOutputStream pout;
PipedInputStream pin;
pout = new PipedOutputStream();
pin = new PipedInputStream();
speaker1 = new speaker(1, pout, pin);
speaker1.start();
speaker2 = new speaker(2, pout, pin);
speaker2.start();
}
}
Output:
======
[124][tmp] ? javac threads.java
threads.java:32: No constructor matching speaker(int, java.io.PipedOutputStream, java.io.PipedInputStream) found in class speaker.
speaker1 = new speaker(1, pout, pin);
^
threads.java:34: No constructor matching speaker(int, java.io.PipedOutputStream, java.io.PipedInputStream) found in class speaker.
speaker2 = new speaker(2, pout, pin);
^
2 errors
[125][tmp] ?
constructor at all. Here is the example (with ==> pointer where defn) and output:
// Destroying a thread.
import java.io.PipedOutputStream;
import java.io.PipedInputStream;
class speaker extends Thread {
private int speakerNumber;
==> public void speaker(int i, PipedOutputStream b, PipedInputStream c) {
speakerNumber = i;
}
public void run() {
int i = 0;
if (speakerNumber == 1)
stop();
while(++i < speakerNumber)
System.out.println("Hello World #" + speakerNumber);
}
}
class demo {
public static void main(String args[]) {
speaker speaker1, speaker2;
PipedOutputStream pout;
PipedInputStream pin;
pout = new PipedOutputStream();
pin = new PipedInputStream();
speaker1 = new speaker(1, pout, pin);
speaker1.start();
speaker2 = new speaker(2, pout, pin);
speaker2.start();
}
}
Output:
======
[124][tmp] ? javac threads.java
threads.java:32: No constructor matching speaker(int, java.io.PipedOutputStream, java.io.PipedInputStream) found in class speaker.
speaker1 = new speaker(1, pout, pin);
^
threads.java:34: No constructor matching speaker(int, java.io.PipedOutputStream, java.io.PipedInputStream) found in class speaker.
speaker2 = new speaker(2, pout, pin);
^
2 errors
[125][tmp] ?