Lab 9 - Inheritance
Lab 9 - Inheritance
Using the extends keyword: The extends keyword has been used to relate the
subclass with the superclass. For example, let’s say we have two classes, named class
A and B, respectively, where class A is the superclass and B is the subclass. Then the
Java syntax will be,
public class B extends A
Using the super keyword (this vs. super): The keyword this refers to the object itself.
It can also be used inside a constructor to invoke another constructor of the same class.
For example, the following code shows the uses of this keyword.
public class Circle { ● this keyword is used to reference
private double radius; the hidden data field radius of the
object being constructed.
public Circle(double radius) {
this.radius = radius;
} ● this(1.0), in this statement, this
keyword is used to invoke
public Circle() { another constructor.
this(1.0);
}
………
……...
}
Lab Tasks: