Hi,
class parent;
.
.
.
endclass
class chaild extends parent;
.
.
.
endclass
In chaild class we also have all features of parent.
I am creating another class
class another;
parent obj;
.
.
.
endclass
Now I am creating object of parent in another class, so i can acess all features of parent,what is the difference between class chaild and another???
Adv thanx : Manju540
I do not like using the terms parent and child as class names when talking about inheritance; it makes is seem like when you construct a child, it is a separate object from the parent. I’d rather use base_c and derived_c to show that derived_c is a modified version of base_c that has added or overridden functionality. And I use _c to distinguish the class type from _h, which is a class variable that has handle to a class object. When you have
class someother_c;
int A;
endclass
class another_c;
int B;
someother_c obj_h;
endclass
another_c another_h;
you are not instantiating someother_c object inside another_c object; you are instantiating a class variable obj_h inside another_c. You have to separately construct someother_c and you can store the handle to it in obj_c. See this post for the distinction. After you construct both objects, you can reference another_h.obj_h.A.
But if instead you have
class someother_c;
int A;
endclass
class another_c extends someother_c;
int B;
endclass
another_c another_h;
When you construct another_c, there is only one object, and you can refer to another_h.A just like another_h.B.