Hi,
I havent read your post fully **lack of time** but I can show you what inheritance is and why you would want it.
If you were creating a game - with lots of types of monsters in it, you might have a class for each type of monster with their attributes, health, magic power, size, x coord, y coord, power etc etc etc.
If you have 20 monsters, you then need 20 of the above code repeated 20 times which is a massive waste.
So you can you use inheritance as follows:
Code:
public class Monster{
String name;
int xCoord;
int yCoord;
int health;
public Monster(String name, int xCoord, int yCoord, int health){
this.name = name;
this.xCoord = xCoord;
this.yCoord = yCoord;
this.health = health;
}
}
public class MonkeyManMonster extends Monster{
Color color;
public MonkeyManMonster((String name, int xCoord, int yCoord, int health,Color color){
super(name,xCoord,yCoord,health); // calls the Monster class constructor
this.color = color;
}
}
}
This means creating a new type of Monster which has the same attributes as all other monsters is now 5 lines of code instead of nearly 20 for example. Another good example is a vehicle class being the superclass - with car, taxi, bus being the subclass - because all cars , taxis buses etc have 4 wheels, a registration plate etc.
Hope this helps