SDSU CS535 Object-Oriented Programming & Design
Fall Semester, 1996
Doc 17, Private Methods & Inheritance

[To Lecture Notes Index]
San Diego State University -- This page last updated Oct 21, 1996
----------

Contents of Doc 17, Private Methods & Inheritance


Doc 17, Private Methods & Inheritance Slide # 1
References

Metroworks Java Compiler


No rule is so general, which admits not some exception
Robert Burton (1576-1640)



Doc 17, Private Methods & Inheritance Slide # 2Listen Here!
Private and Dynamic Method Binding

Since a private method can not be called from the child, when an inherited method (foo) calls a private method (Parent.bar), the parent private method is always the one called

class Parent
   {
   public void foo() 
      { 
      bar(); 
      };

   private void bar() 
      { 
      System.out.println( "Parent bar"); 
      };
   }

class Child extends Parent
   {
   public void bar() 
      { 
      System.out.println( "Child bar");
      };
   }

class Test 
{
   public static void main( String args[] )
   {
   Parent trouble = new Child();
   trouble.foo();
   }
}

Output
Parent bar


----------