public class PlayThread extends Thread{ String songname; public PlayThread(String tname,String songname){ super(tname); this.songname=songname; } public void run(){ System.out.println("In Thread-"+this.getName()); for(int i=1;i<=10;i++){ System.out.println("Playing"+songname); } System.out.println("Done Playing"); } } public class Download extends Thread { String songname; public Download(String dname,String songname){ super(dname); this.songname=songname; } public void run(){ System.out.println("In Thread-"+this.getName()); for(int i=1;i<=10;i++){ System.out.println("Downloading"+songname); } System.out.println("Downloaded"); } } public class Main { public static void main(String[] args) { System.out.println("In Main Thread"); PlayThread t1=new PlayThread("Play-Thread", "song-1"); Download t2=new Download("Downloading Thread", "song-1"); t1.start(); t2.start(); System.out.println("DONE"); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter