Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

A research question in classes

  Asked By: Willie    Date: Aug 17    Category: Java    Views: 596
  

I got a question for u, and i hope u ppl will try to find its answer
and discuss it with me.
Q: We have learnt that private members of a class are not inherited
in the child class, but look at the following simple example and
think over it:

class test{
private int a;
public void look(){
a=16;
System.out.println(a);
}
} //End of class

class test2 extends test{
public void go(){
a=420;
system.out.println(a);
}
} //End of class

now if we make an object of class test2 in main as:
test2 obj=new obj();
and then write the following statement:
obj.what();
then it will print: 15
what we did is that we called what() of test2 coz its also a member
of test2. but variable 'a' is private and is now inherited to child
then how can we access from what() of test2 as its not inherited.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on A research question in classes Or get search suggestion and latest updates.




Tagged: