Hi,
Before you consider the code that follows, there are two main points to note:
1. Inner classes of a class can access the private members of the outer class.
2. When you have a subclass extending the superclass, and you try to override the method in the parent class, the access modifier cannot be made more restrictive, but it can be made more public.
The following is a code that proves that the
Java compiler allows an inner class to extend the outer class.
Now, consider the following code:
<CODE>
public class check
{
public class myabstract
{
int i;
String s;
private void mymethod()
{
System.out.println("In myabstract::mymethod()");
}
public void anothermethod()
{
System.out.println("In myabstract::anothermethod()");
}
class myinner extends myabstract
{
private void mymethod()
{
System.out.println("In myinner::mymethod()");
}
}
}
}
</CODE>
The above code also shows one more important thing:
A PRIVATE METHOD CAN BE OVERRIDDEN IN A SUBCLASS!!(Here the subclass is the inner class and it is able to access all the methods(including private) of the parent class.)
Also, any method that is allowable to be overridden in the subclass can be allowed to be marked as abstract in the parent class. Then, why doesn't the compiler allow a private method to be declared abstract???
Thanks in advance,
Aparna