Email address:
Password:
SCJP/OCPJP 1.6 certification
Practice Exams and Training
SCJP Online Training » Discussions

explanation confusing

good afternoon, i fail to understand this question, class B as an inner class its suppose to have access even to the private methods of the of the outer class, which is in this case class A

I agree that this explanation is rather ambiguous when it says the class B does not have access to the members in the super class A. It's correct that the overriding rules do not apply here, but it's not due to the invisibility of super class members. The rule is if the super class method is private, it cannot be overridden by any means. This also comes with the effect that none of the overriding rules gets apply in such cases.


For instance, consider this one:


public class Node{

   private String returnMethod() {
      return "s";
   }
	  
   class NodeInner extends Node {
      private int returnMethod(){
         return 0;
      }
   }
	
}


As you can see the returnMethod() in the super class has the return type of String. And the method with the same name in the sub class has the return type of "int". Now, this is not something that would compile if there was an override. But this is not an example to overriding because the keyword private in the super class method indicates it is not subjected to be overridden.


ExamLab © 2008 - 2024