My teacher assigned a program that has quite a few classes but just to grasp the gist of overriding i'll only use 3 in this thread.
Basically the 3 classes I want to use are my superclass WoWCharacter which is extended by class Horde which is then extended by the class Orc. For my overriding method my WoWCharacter class is supposed to have an abstract speak method which is then supposed to be overridden by my Orc's speak method and is supposed to have the output of "Grrrr". Like I said headfirst really doesnt have examples of how to override and I jsut can;t seem to understand it.
public abstract class WoWCharacter {
public static void main(String[] args) {
// TODO Auto-generated method stub
int hpGen = (int)(Math.random() * 501); // Generates health
int level = (int)(Math.random() * 81); // gens level
int race = (int)(Math.random() * 4)+ 1; // gens race 1 orc 2 troll 3 gnome 4 dwarf
System.out.println(race);
if (race ==1) {
Orc zug = new Orc(hpGen);
}
public abstract void speak();
That is my WoWcharacter Class there is more to it but that has to do with the other aspects of the program. Also ignore the random generators.
public class Orc extends Horde {
int health;
int level;
public Orc(int gethp) { // Health object and constructor
System.out.println("You've made an orc.");
health = gethp;
System.out.println("Health is " + health);
}
public void speak() {
System.out.println("Grrr");
}
}
And here is my orc class but when i run my program it wont print the "Grrr" I so desire it to print.
I offer my thanks to you in advanced as I know this is a helpful community.

New Topic/Question
Reply




MultiQuote




|