-1
class A
{
}
class B extend A
{
    int i;
    int j;
}

Can a class have an IS-A Relationship with itself? In this question, B is an A, right? But can class B have an IS-A relationship with class B?

Pang
  • 9,564
  • 146
  • 81
  • 122
Amit2311
  • 93
  • 1
  • 7

1 Answers1

1

It's an identity (and tautology) - an object of type B will always be able to describe itself as an object of type B.

The further extensions of the is-a relationship pertain to hierarchies of inheritance; that is to say, since B extends A, B is-an A. This allows you to write the following expression:

A anA = new B();

But B is a B too. It hasn't lost that part of its identity because it now inherits from another class.

Makoto
  • 104,088
  • 27
  • 192
  • 230