Re: copying subclass object
Solved ,,
i put a constructor In Aclass with arguement of Bclass, to when it is called it will copy subclass object ..
Aclass ( Bclass obj){
x = obj.x;
}
Solved .
but is it possible to do this ??
Super class object = subclass object ?
Re: copying subclass object
So when you have a superclass extended by a subclass, the subclass is a type of the superclass. But this does not mean that you can save the superclass as a type of the subclass.
Consider your sample...
Class B extends Class A. Ok so far so good. Now all objects of class B are also objects of class A. Anywhere you expect to find a class A object in your code, you can throw in an object of class B.
Now consider this...
Class C also extends class A. An object of class C is also class A.
Now compare B to C. Both B and C are of type A, but B and C may not be used for one another, unless the type you expect is type A. If your code wants a B object, you must provide a B object, and if your code requires a C object you must provide a C object.
What you have done is create a superclass (A) dependant on a subclass (B). This limits the superclass to always include the subclass B and therefore really takes away the meaning of extending class B from A to begin with. That makes it seem to me that possible your B class should have been the super class instead. (Maybe... just guessing).
If you want to provide some real class samples of what you are trying to do, I can explain with more details. Basically I am asking what purpose do you have in extending a class, and then using the extended class in the super class? Its like you cut something into two parts, just to glue them back together.
Re: copying subclass object
thanks for Explanation. and details ..
:)