ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
We have two methods to create methods the threads.
1. Implementing runnable interface
2. Extending to thread class and overriding run method.
Among these two which one is better and why?
Please explain me in detail.
 Question Submitted By :: Shivaprasad
I also faced this Question!!     Rank Answer Posted By  
 
  Re: We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.
Answer
# 1
implementing runnable interface is better than extending to
thread why because if u implements from runnable interface u
can have chance to extend one more class.but incase of
extending thread this facility is not there
 
Is This Answer Correct ?    2 Yes 0 No
Venkat
 
  Re: We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending to thread class and overriding run method. Among these two which one is better and why? Please explain me in detail.
Answer
# 2
The Runnable technique is particularly convenient when you 
want to create just a single thread to carry out a specific 
task. The run() method will have access to the instance 
variables in the Runnable object. For example, a common 
approach to applet animation is to make the applet 
Runnable. The run() method then has access to the applet's 
variables, which could be parameters passed in the applet 
tags or set by the user via the graphical interface. 

Note also that since there are no restrictions on the 
number of interfaces that a class can implement, it is easy 
to add Runnable to a class.

On the other hand, if you want to create multiple threads, 
then it usually makes more sense to use a Thread subclass. 
This helps to better conceptualize the threads as 
independent objects, each with its own independent sets of 
variables (as opposed to sharing variables in the Runnable 
object.) You can set the values of whatever parameters they 
need via their constructors or "setter" methods.
 
Is This Answer Correct ?    0 Yes 0 No
Mira
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Difference between an argument and a parameter? HCL4
How u dubugg ur project? iFlex1
Is 'null' a keyword?  3
what is Remote Reference Layer ?  1
is this possible to create an array of 0 length? if so how? if not so why? coz we have an array in main() likw this "static void main(String [] s) then what it signifies? Hexaware2
what is difference between type 4 driver and type 1 driver? CMC2
String is an immutable object. Then how can the following code be justified. String s1 = ?ABC?; String s1 = s1+?XYZ?; s.o.p(s1); The output is ABCXYZ, which is the value of s1 ? Flextronics5
What are interfaces?  1
What is meant by Encapsulation? Can you write a class to explain encapsulation? Ness-Technologies8
List interface?  2
what is the use of reference variable  2
suppose in a class there is a code like this: { Set hs=new Hashset(); hs.add(new Emp("kathy",1000)); hs.add(new Emp("kathy",2000)); } how can u avoid the above code in your class as set won't allow duplicate objects?  2
When we can access the static data member without creating the object what is the need of the object in java. ssinformatics4
What is Transient and volatile iFlex9
whst is encapsulation?when u encpsulate actually while devoloping code? AMDOC5
If your team member writes code with lots of static variables and static methods, will it cause any side effects? KPIT1
Difference between Web-based applications,Client- Server applications and Distributed applications? Infosys2
how can you retrive information from database by using hashmap/arraylist ,plz explain with example briefly? Satyam1
What is the root class for all Java classes?  4
What is the is a and has a relation ship in oops concept in java? BearingPoint5
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com