Inheritance

Inheritance

Inheritance is where one class extends another or implements a interface, so in the case of extension it can call that classes methods, without making a object of the class. Other benefits include being able to use the superclass as a general class so you can have a parameter include the superclass and all subclasses of the superclass.

For example:

public class Balloon

public class RoundBalloon extends balloon

public class SquareBalloon extends balloon

public void draw(balloon k)

{

}

could take Balloon, SquareBalloon and/or RoundBalloon.

The drawback of inheritance in Java is that only one superclass can be extended so a class can’t inherit from multiple classes. However several interfaces can be implemented at the same time to (some extent) mimic multiple inheritance.

Related links are below:

Interfaces:

classes(not done yet):

One thought on “Inheritance

Comments are closed.