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                      
tip   SiteMap shows list of All Categories in this site.
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
Hi, well i am unable to understand that why it is mandatory
to have same hashcode, if two objects are same?

Thanks in advance.
 Question Submitted By :: Tanzeem.akhtar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
Answer
# 1
NO No NO....
Check it once..
If there r  two same objects, there must be a diffent 
hashcode to them....
U never find same hashcode to any two objects
 
Is This Answer Correct ?    0 Yes 0 No
Venkateswara Reddy
 
  Re: Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
Answer
# 2
If two objects are equal then there hashcode must same.
 
Is This Answer Correct ?    1 Yes 0 No
Prasanna
 
 
 
  Re: Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
Answer
# 3
As the JVM assigns the hashcode to an object value and not
the reference the hashcode for the same object will be same.
the equals() method of the object class uses this hashcode
to evaluate if the objects have same value. therefore

Object o1 = new String("ABC");
Object o2 = "ABC";

 /**
  * will have the same hashcode 
  * therefore when we do..
 */
if(o1 == o2){
 System.out.println("The object reference is same");
}else if(o1.equals(o2)){
 System.out.println("The object has same value");
}

 /**
  * The output is 
  * The object has same value
 */
 
Is This Answer Correct ?    1 Yes 0 No
Rajshekaran Pillai
 
  Re: Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
Answer
# 4
Hi,

No. Never same hash code to 2 same objects. every object is 
having it's own hash code.
 
Is This Answer Correct ?    2 Yes 0 No
Nalluri
 
  Re: Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects are same? Thanks in advance.
Answer
# 5
Hi,

No. Never same hash code to 2 same objects. every object is 
having it's own hash code.
 
Is This Answer Correct ?    0 Yes 0 No
Nalluri
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is ennumaration? AMDOC1
How does a try statement determine which catch clause should be used to handle an exception?  2
What is Marker interface in java? and what is clone? Wipro7
what is the use of private constructor in core java? Satyam3
which class to use when concatenating strings in a loop. IBM2
When is an object in the mean to garbage collection?  3
How to override a equals() method and what is the use?  1
What is the Layout for ToolBar?  1
Hi ,i convert contrller as jSp And presentation as servlet ...will it do? if so what are advantage and idsadvantages IBM1
When will we use class loader?  1
How does serialization work Ordain-Solutions2
what is multitherading Tech-Mahindra2
different types of threads? TCS7
How to add two numbers with out using Arithmetic , union operators in java....? But we can use bitwise operators... but how...? CTS2
class A{ class B{ } } in which name u save the file,its the program compile? HCL6
While opening the file, what type of exceptions can be caught?  3
why Runnable interface is preferable than extending the Thread class? Wipro5
Explain difference between final, finally and finalize?  2
what are depricated methods in threads and explain the lifecycle methods  5
perpare on factorypattern,linklist wothout using collection, (multitharding ie create producer/customer therad producer create Queue continuesly,consumer consume queue, consumer wait if queue is full,producer wait if queue is empty),diff betn sleep(1000)&wait(1000) these r the main Q ask in huawei(2008) Huawei1
 
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