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   To Refer this Site to Your Friends   Click Here
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
How to override a equals() method and what is the use?
 Question Submitted By :: Tek
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to override a equals() method and what is the use?
Answer
# 1
equals is a method in Object class..
By default in java all the classes extend object class so 
any two object can be compared using the equals method...

Provided user implement their own equals method(Override), 
because the original equals method compares two objects by 
their reference..

If you have a class

class A
{
  int value;
    p s v m(String args[]){
    A obj1= new A();
    abj1.value = 10;
    A obj2= new A();
    abj2.value = 10;
    
   // now if try to compare these two classes 

    sop(obj1.equals(obj2))  // Result will be always false
 }                          //unless you override
                             the equals method
 
    boolean equals(A a){
      if (a.value == this.value)
       return true;
      else
        return false;
    }//Placing this method in the above class will override 
        the equals method and you will be able to compare 
        actually the properties of those two object not 
        their references.
 
Is This Answer Correct ?    5 Yes 0 No
Rohan
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what is connection pooling with example? AMDOC1
What is user defined exception?  4
how many design pattern r there? and wht design pattern u use and why ? HP5
Accenture NJ mostly ask question on Collection like 1)How to sort Objcts and how treeset sort them 2)Explain mechanism of Hashcode finding in Java 3)Name some of the Sorted collection. Accenture2
Linked List reverese program Bally-Technologies1
What is a layout manager?  1
Which are thin and thicK wrapper Class's in Java?  1
10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? a)Direction d = NORTH; b)Nav.Direction d = NORTH; c)Direction d = Direction.NORTH; d)Nav.Direction d = Nav.Direction.NORTH;  1
Why do we use public static with the main function in Java? Infosys7
What will happens if you opened Internet Explorer 4 times?  2
Explain the difference between the Boolean & operator and the && operator?  1
what is ennumaration? AMDOC1
What is a compilation unit?  2
What is Transient and volatile iFlex9
What is a reflection package?  2
How multipleInheritance is possible in java? Satyam16
What are the interfaces defined by Java.lang package?  1
How many objects are created for a singleton class Ness-Technologies4
What is deadlock and how to avoid this?  2
What is the difference between throw and throws? What is the similarity between try and throw?  2
 
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