I have to create UML diagram for the two Java program/code written below. My queries are:
- Is a sub class of an interface also an interface?
- Is a class implementing Runnable Interface also an interface?
- Can't methods/functions be called Operations of a class?
- Are global variables the only attributes of a class or local variables within a function can also be called so?
- In the 2nd Program the author is sending an object to the Thread constructor. Is it correct?
Aside: Can someone body please draw the UML for the two programs? I'm having hard time with understanding Threads, interface & related keywords like extends, implements.
JAVA CODE #1
public class RunThreads
{
public static void main(String[] args)
{
SomeThread p1=new new SomeThread(1);
p1.start();
SomeThread p2=new new SomeThread(2);
p2.start();
SomeThread p3=new new SomeThread(3);
p3.start();
}
} // end class RunThreads
public class SomeThread extends Thread {
{
int myID;
SomeThread(int id) {
this.myID=id;
}
public void run() {
int i;
for(i = 1; i < 11; i++)
System.out.println("Thread" + myID + ": " + i);
}
} // end class SomeThread
JAVA CODE #2
public class RunThreads2
{
public static void main(String[] args)
{
Thread p1 = new Thread(new SomeThread2(1));
p1.start();
Thread p2 = new Thread(new SomeThread2(2));
p2.start();
Thread p1 = new Thread(new SomeThread2(3));
p3.start();
}
} // end class RunThread2
class SomeThread2 implements Runnable {
int myID;
SomeThread2(int id) {
this.myID = id;
}
public void run() {
int i;
for(i=1; i<11; i++)
System.out.println("Thread " + myID + ": " + i);
}
} // end class SomeThread2