jgh
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.
Circle
and Cylinder
: Cylinder
is a subclass of Circle
. We can say that Cylinder
"is-a" Circle
(actually, it "is-more-than-a" Circle
). Subclass-superclass exhibits a so called "is-a" relationship.Cylinder
, and assign it to a Circle
(its superclass) reference, as follows:// Substitute a subclass instance to its superclass reference
Circle c1 = new Cylinder(5.0);
You can invoke all the methods defined in the Circle
class for the reference c1
, (which is
actually holding a Cylinder
object), e.g. c1.getRadius()
and c1.getColor()
. This is because a subclass instance possesses all the properties of its superclass.Cylinder
class for the reference c1
, e.g. c1.getHeight()
and c1.getVolume()
. This is because c1
is a reference to the Circle
class, which does not know about methods defined in the subclass Cylinder
.c1
is a reference to the Circle
class, but holds an object of its subclass Cylinder
. The reference c1
, however, retains its internal identity. In our example, the subclass Cylinder
overrides methods getArea()
and toString()
. c1.getArea()
or c1.toString()
invokes the overridden version defined in the subclass Cylinder
, instead of the version defined in Circle
. This is because c1
is in fact holding a Cylinder
object internally.