Rohit Bajaj
asked on
Encountring error while implementing functions in abstract class
Hi,
I have an abstract class A
which has the following functions :
1) private B()
2) abstract C()
Now when i create an object of this class somewhere else like :
A a = new A()
{
C()
{
//i am unable to access private functions and variables from here
}
}
The issue i am encountring is that why i am unable to call private methods or access private variables from inside the functions ? why does java not allow this .. it seems bit odd to me.. Please explain..
Also whats the solution if i want to access a fucntion
Thanks
I have an abstract class A
which has the following functions :
1) private B()
2) abstract C()
Now when i create an object of this class somewhere else like :
A a = new A()
{
C()
{
//i am unable to access private functions and variables from here
}
}
The issue i am encountring is that why i am unable to call private methods or access private variables from inside the functions ? why does java not allow this .. it seems bit odd to me.. Please explain..
Also whats the solution if i want to access a fucntion
Thanks
ASKER
HI,
If i am creating an object from a subclass of A then how is it represented. I mean there is one way in which
i can explicity define a class X implementing the Abstract class A. This will have a name etc. and I know i have created an object of type X whereas in above case what is the class whose object is created there is no name specified.
If i am creating an object from a subclass of A then how is it represented. I mean there is one way in which
i can explicity define a class X implementing the Abstract class A. This will have a name etc. and I know i have created an object of type X whereas in above case what is the class whose object is created there is no name specified.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
Personally i avoid anonymous classes - they militate against self-documenting code and produce nastily named binaries which can be more easily overlooked when moved around
Personally i avoid anonymous classes - they militate against self-documenting code and produce nastily named binaries which can be more easily overlooked when moved around
You're not actually. You're creating an object from a subclass of A. If you want to override and invoke its methods irrespective of package location, you need to mark the methods of the base class with the modifier protected or public