S
sujee
hi i have a problem. pls help.
class A {
private int i;
void seti(int x) {
i = x;
}
int geti(){
return i;
}
}
class B extends A {
}
class PrivateMember {
public static void main(String args[]) {
B subOb = new B();
subOb.seti(10);
System.out.println(subOb.geti());
}
}
In the above program the super class 'A' have an private member 'i'.
since it is a private member, 'i' is not a member of sub class 'B'. and
in the super class it have 2 methods seti() and geti() to set and get
the 'i'. In the 3rd class 'PrivateMember', it create an subclass
instance and run both methods. since 'i' is not an member of subclass,
how the subclass instance set and get 'i'. when creating an instance it
allocates the memory locations for its member. but 'i' is not a member.
where is the location of the 'i' that is set by seti method? pls help
class A {
private int i;
void seti(int x) {
i = x;
}
int geti(){
return i;
}
}
class B extends A {
}
class PrivateMember {
public static void main(String args[]) {
B subOb = new B();
subOb.seti(10);
System.out.println(subOb.geti());
}
}
In the above program the super class 'A' have an private member 'i'.
since it is a private member, 'i' is not a member of sub class 'B'. and
in the super class it have 2 methods seti() and geti() to set and get
the 'i'. In the 3rd class 'PrivateMember', it create an subclass
instance and run both methods. since 'i' is not an member of subclass,
how the subclass instance set and get 'i'. when creating an instance it
allocates the memory locations for its member. but 'i' is not a member.
where is the location of the 'i' that is set by seti method? pls help