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
References
Metroworks Java Compiler
No rule is so general, which admits not some exception
- Robert Burton (1576-1640)
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