Got to create a small presentation on java inheritance, got some basic information about it but need to include example programs and talk about how they work. Iv got a small program below which is supposed to output an oblong but it doesnt for some reason.
public class oblong { private double length; private double height; public oblong(double lengthIn, double heightIn) { length = lengthIn; height = heightIn; } public double getlength() { return length; } public double getheight() { return height; } public void setlength(double lengthIn) { length = lengthIn; } public void setheight(double heightIn) { height = heightIn; } public double calculateArea() { return length * height; } public double calculatePerimeter() { return 2 * (length + height); }
public class ExtendedOblong extends oblong { private char symbol; public ExtendedOblong(double lengthIn, double heightIn, char symbolIn) { super(lengthIn, heightIn); symbol = symbolIn; } public void setSymbol(char symbolIn) { symbol = symbolIn; } public String draw() { String s = new String(); int l, h; l = (int) getlength(); h = (int) getheight(); for (int i = l; i <= h; i++) { for (int j = l; j <= l; j++) { s = s + symbol; } s = s + '\n'; } return s; } public static void main(String[] args) { ExtendedOblong extOblong = new ExtendedOblong(10,5,'*'); System.out.println(extOblong.draw()); extOblong.setSymbol('+'); System.out.println(extOblong.draw()); } }
Does anyone know why this code will not output an oblong, and also if anyone has any example programs of java inheritance or any information about it can you please post it.
Many Thanks.