Private member

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top