I am currently working on a hibernate project(EJB and JSF), and i have multiple java classes. The data of parent is being change in the front end with JSF, however, it is not updating in the child class. I need to access the data in the child class to do some calculation. Any Ideas as to how to pass the value of a variable from a parent class to a child class?
Thanks in advance
Example:
Parent class
public class parent {
private String x = "a+";
public String getx(){
return x;
}
public void setx(String x){
this.x = x;
}
}
child class
public class child extends parent{
private String z;
public String getZ(){
System.out.print(getx());
return z;
}
}
main class
public static void main(String[] args) {
parent p = new parent();
System.out.println("Original" + p.getx());
p.setx("z");
System.out.println(" Add z" +p.getx());
child c = new child();
System.out.println("child getx" +c.getx());
p.setx("zZ");
System.out.println("child getz" +c.getZ());
}
}
result. Original a+
Add z z
child getx a+
a+child getz null