multithreading without importing Thread class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stmfc
    New Member
    • May 2007
    • 65

    #1

    multithreading without importing Thread class

    how can a multithreaded code can be compiled succesfully without importing Thread class?

    the example below is taken from marcus green mock exam 1:

    Code:
    public class Rpcraven{
    	public static void main(String argv[]){
    	Pmcraven pm1 = new Pmcraven("One");
    	pm1.run();
    	Pmcraven pm2 = new Pmcraven("Two");
    	pm2.run();
    
    	}
    }
    
    class Pmcraven extends Thread{
    private String sTname="";
    Pmcraven(String s){
    	sTname = s;
    
    }
    public void run(){
    	for(int i =0; i < 2 ; i++){
    		try{
    		 sleep(1000);
    		}catch(InterruptedException e){}
    
    		yield();
    		System.out.println(sTname);
    		}
    
    	}
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    The Thread class is in the java.lang package which gets imported implicitly, just
    like String, Object etc.

    kind regards,

    Jos

    Comment

    • stmfc
      New Member
      • May 2007
      • 65

      #3
      thanks for your reply.
      one more question, what is the full list of classes imported implicitly?
      all classses in java.lang package?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by stmfc
        thanks for your reply.
        one more question, what is the full list of classes imported implicitly?
        all classses in java.lang package?
        I don't know all classes in the java.lang package by head but yes, they're all
        implicitly imported; it is as if the first line in your program looks like this:

        [code=java]
        import java.lang.*;
        [/code]

        kind regards,

        Jos

        Comment

        Working...