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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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!
 
Onion rings are vegetable donuts. Taste this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic