{"id":757,"date":"2010-08-16T22:56:57","date_gmt":"2010-08-16T17:26:57","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=757"},"modified":"2010-08-16T22:56:57","modified_gmt":"2010-08-16T17:26:57","slug":"anonymous-classimplements-interface-methods-of-threads","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/anonymous-classimplements-interface-methods-of-threads\/","title":{"rendered":"Create Thread using Anonymous class and Interface"},"content":{"rendered":"<p>Create thread using Anonymous class:<\/p>\n<p><strong>Anonymous Class<\/strong><\/p>\n<p>Explanation:- \u00a0A Class which does not have any name is known as anonymous\u00a0class.<\/p>\n<p>Q. Write a program to create thread using anonymous class\/local class.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass testAno\n{\n  public static void main(String args&#x5B;])\n  {\n     Thread t =new Thread(new runnable(){\n     public void run()\n     {\n          System.out.println(&quot;I am in Thread&quot;);\n     }\n    });\n\n    t.start();\n}\n}\n<\/pre>\n<p>O\/P:- \u00a0 \u00a0I am in Thread<\/p>\n<p>Create Thread Using Interface \u00a0 OR  Runnable Interface:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nclass Method\n{\n  public static void main(String args&#x5B;])\n  {\n     TestThread runnable_obj=new TestThread();\n     Thread t=new Thread(runnable_obj);\n     t.start();\n  }\n}\n\nclass TestThread implements Runnable\n{\n  public \u00a0void run()\n  {\n     System.out.println(&quot;In Thread Main&quot;);\n  }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Demonstration of creating Thread by Anonymous class and Interface<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[122,198],"class_list":["post-757","post","type-post","status-publish","format-standard","hentry","category-java","tag-interface","tag-thread"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1820,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-threading-executor-framework-and-callable-interface\/","url_meta":{"origin":757,"position":0},"title":"Java Threading &#8211; Executor Framework and Callable Interface","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Java Threading - Executor Framework and Callable Interface with example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":724,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/simple-threading-techniques\/","url_meta":{"origin":757,"position":1},"title":"Thread, Life Cycle of Thread","author":"Jitendra","date":"August 7, 2010","format":false,"excerpt":"What is Thread? Life cycle of thread. Difference in start() and run() method of Thread. By Default how many thread runs?","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1825,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-thread-timertask\/","url_meta":{"origin":757,"position":2},"title":"Java Thread &#8211; Executor framework, Timer and TimerTask","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Tutorial and example of Executor framework, Timer and TimerTask over Thread","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Animation of ProgressBar in Swing Using TimerTask","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Animation-of-ProgressBar-Swing-Using-TimerTask.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1629,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/nested-class-and-its-necessity-with-example\/","url_meta":{"origin":757,"position":3},"title":"Nested Class and its necessity with example","author":"Jitendra","date":"March 11, 2011","format":false,"excerpt":"Example and Introduction of Nested classes in JAVA and there Types","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Nested Class in JAVA","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Nested-Class-in-JAVA.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1816,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/daemon-thread-java\/","url_meta":{"origin":757,"position":4},"title":"Daemon Thread","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Example and Explanation of Daemon thread in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":748,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/producer-consumer-problem\/","url_meta":{"origin":757,"position":5},"title":"Thread Synchronization","author":"Jitendra","date":"August 7, 2010","format":false,"excerpt":"Describes Synchronization, Producer and Consumer Problem, wait(), notify(), InterThread Communication","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=757"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/757\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}