Wednesday, August 13, 2014

Inheritance super variables help.




Hey guys, I'm writing a simple program in which I have a super class Person, inherited by the subclasses Customer and Employee (they inherit the variables ID, name and surname).






Java Code:






public class Person {

int id;
String name;
String surname;

public Person () {
}
public Person (int i, String n, String s) {
id = i;
name = n;
surname = s;
}






Java Code:






public class Employee extends Person implements Serializable {

String username;
String password;
String date;
int hpw;
int recordSold;
float hourPay;

public Employee() {
}

public Employee (String u, String n, String s, String p, int i, int h, String d, int rSold, float hPay) {
username = u;
super.name = n;
super.surname = s;
password = p;
super.id = i;
hpw = h;
date = d;
recordSold = rSold;
hourPay = hPay;
}




However the problem is here: when I try to get the variables ID, name and surname through my main class, they fail to return (0,null,null). Why is this? I have get-Methods in my subclasses which should return the super variables, but they are not. Thanks for your time and patience.



Java Code:






public String getUser() {
return username;
}

public String getName() {
return super.name;
}







No comments:

Post a Comment