Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

overriding equals

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Report post to moderator
class test
{
static int maxElements;


test(int maxElements)
{
this.maxElements = maxElements;
}

}
public class qequals
{
public static void main(String[] args)
{

test a = new test(100);
test b = new test(100);
}
public boolean equals(test b)
{

...............................
.......................................
..........................

System.out.println("Objects have the same values");
else
System.out.println("Objects have different values");
}
}
could anyone show me how to overide equals here
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator

class Test
{
static int maxElements;
Test(int maxElements)
{
this.maxElements = maxElements;
}
public boolean equals(Test b)
{
if(maxElements==b.maxElements)
return true;
else
return false;
}
}
public class qequals
{
public static void main(String[] args)
{
Test a = new Test(100);
Test b = new Test(100);
if(a.equals(b))
System.out.println("Objects have the same values");
else
System.out.println("Objects have different values");
}
}
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Report post to moderator
I am closing this thread since the exact same topic has been discussed in this post. Feel free to continue the conversation there!
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!