Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Now when i create an object of this class somewhere else like :

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
Avatar of Rohit Bajaj

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.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)

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