How can I casting from parent class to children class
807580Jun 22 2010 — edited Jun 22 2010Dear,
Could someone help me to casting from parent class to children class.
I have class like this
class parent{
String name;
String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class children extends parent{
String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public children() {
}
public children(parent p) {
//Do init super class here
}
}
//--------------------------------
In the constructor
public children(parent p) {
//Do init super class here
}
I like to init super class by object p (this is instance of parent class). The way to do is using:
public children(parent p) {
super.setId(p.getId());
super.setName(p.getName());
}
But I don't like this, because, for example I have parent class with over 30 proberties, it take time to do like that.
There are any way to use super operation to init parent class, for example super = p;
Could you show me the way.
Thanks alot