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 ?    1 Yes 0 No
Rohan
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Is Java is 100% pure OOPS? Explain?  11
When you Click a Button, What event will be fired?  1
how you will prevent inheritance is there any other way other than inheritance? Wipro3
Why are the methods of the Math class are static?  1
what are the jsp tags with example? Photon1
how exactly garbage collection take place?  4
Does Java support multiple Inheritance?  4
Can we declare static variables in JSP page. TCS2
Hey buddy.. can you please tell me about the use of marker interface? And is there any link between marker interface and factory methods? Thanks in advance.  2
what is business objects?  1
Does a class inherit the constructor of its super class?if it does, how can you hide that constructor? if it doesnot how can you call it from the sub class?  1
what is the JNDI?  3
why the constructor should be used in class,if there is no constructor what will happen?  3
Explain about GridBag Layout?  1
How many methods does cloneable interface contains?  2
What are batch updates. in jdbc Corent-Technology1
Is 'sizeof' a keyword?  3
Explain Stream Tokenizer?  2
Why would you desing a J2EE application so user data is entered by way of a JSP page and managed by an underlying Java Beans class? Adobe2
explain the concept of inheritance with an example? Polaris3
 
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