Tuesday, 6 August 2013

Java: Extended class issues.

Java: Extended class issues.

I have had some issues involving code that accesess variables defined in a
superclass that were later revised in a child class. Ie
public class Derp {
String name = " ";
int IQ = 0;
}//end of class
public class Aaron extends Derp {
{
Name = "Aaron";
IQ = 10;
}
}//end of class
public class Main {
public static void main(String args[]) {
System.out.println("Hi, my name is: " + Aaron.name + "!\n");
}
This code will print: Hi, my name is !
instead of: Hi, my name is Aaron!
my full code is here: http://pastebin.com/6nPGwJQe
reddit was no help so I now turn to you. (not that you arent helpful, but
I just use reddit more so it is more convenient).
PS: My first question on stackoverflow!

No comments:

Post a Comment