- #1
- 1,231
- 0
There is essentially no difference between a superclass of a class and a public member variable of that class. For example, if you define
then defining
provides all the same functionality as defining
The only difference is a slight one of notation.
So why have subclasses at all? Are there object oriented languages that explicitly take advantage of this?
Code:
public class Blob
{
public int mass;
}
Code:
public class Ball extends Blob
{
public int radius;
}
Code:
public class Ball
{
public Blob b;
public int radius;
}
So why have subclasses at all? Are there object oriented languages that explicitly take advantage of this?