class Alpha
public class Alpha
{
//matches method
public boolean matches(Alpha other)
{
if (this.getClass() == other.getClass())
{
//System.out.println(this.getClass() + " " + other.getClass());
return true;
}
return false;
}
}
class Beta
public class Beta extends Alpha
{
protected int rank;
//constructor
public Beta(int rank)
{
this.rank = rank;
}
//matches method
public boolean matches(Alpha other)
{
super.matches(other);
//if(rank == other.rank)
return true;
//return false;
}
}
class Test
class Test
{
public static void main(String[] args)
{
Alpha c0 = new Alpha();
Alpha c1 = new Alpha();
Alpha b2 = new Beta(1);
Alpha b3 = new Beta(2);
/***
* check to see if c0 and c1 are of the same class
*
* should return 'PASS'
***/
if (c0.matches(c1))
System.out.println("matches: PASS");
else
System.out.println("matches: FAIL");
/***
* check to see if c0 and c1 are of different classes
*
* should return 'FAIL'
***/
if (!c0.matches(c1))
System.out.println("matches: PASS");
else
System.out.println("matches: FAIL");
/***
* check to see if c1 and b2 are of the same class
*
* should return 'FAIL'
***/
if (c1.matches(b2))
System.out.println("matches: PASS");
else
System.out.println("matches: FAIL");
/***
* check to see if b2 and b3 are of the same class AND have the same rank
*
* should return 'FAIL'
***/
if (b2.matches(b3))
System.out.println("matches: PASS");
else
System.out.println("matches: FAIL");
}
}

New Topic/Question
Reply



MultiQuote




|