interface - Creating UML for the Java code -


i have create uml diagram 2 java program/code written below. queries are:

  • is sub class of interface interface?
  • is class implementing runnable interface interface?
  • can't methods/functions called operations of class?
  • are global variables attributes of class or local variables within function can called so?
  • in 2nd program author sending object thread constructor. correct?

aside: can body please draw uml 2 programs? i'm having hard time understanding threads, interface & related keywords 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; < 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 

is sub class of interface interface?

there no such thing subclass of interface. can extend interface interface, or can implement interface class.

is class implementing runnable interface interface?

no - it's class. interface defined interface, not class.

can't methods/functions called operations of class?

sure - method/function/operation - sounds reasonable synonyms me. internally, java calls them methods (see reflection related javadoc)

are global variables attributes of class or local variables within function can called so?

i assume you're referring class attributes objects/primitives owned class instance - in first example, myid in somethread class. local variables within method accessible within method (for example, i in run method in same class), , not class attributes.

in 2nd program author sending object thread constructor. correct?

yes; new somethread2(3) returns instance of somethread, object.

can body please draw uml 2 programs?

not likely. sounds homework.


Comments