Cannot call a base class private protected (protected private) member function. When you
compile, you receive compiler error message:
No method matching (function signature) found in (base class).
Steps to reproduce
Compile the following code
/* Access modifier tests
* This tests same package access modifiers for member functions
*/
class AccessTest
{
public static void main(String args[])
{
//
BaseClass baseClass = new BaseClass();
baseClass.func("Kevin");
// this should be okay
baseClass.protectFunc("Arthur");
// this should generate a compiler error
// baseClass.privFunc("Frank");
// this should generate a compiler error
// baseClass.privProtectFunc("Jim");
// now lets try this with a derived class
DerivedClass derivedClass = new DerivedClass();
derivedClass.func("Eric");
}
}
class BaseClass
{
public void func(String s)
{
System.out.println("BaseClass.func() " + s);
}
protected void protectFunc(String s)
{
System.out.println("BaseClass.protectFunc() " + s);
}
private void privFunc(String s)
{
System.out.println("BaseClass.privFunc() " + s);
}
// this syntax should limit other functions in the default
// package from calling this function, but allow
// derived classes to call it.
private protected void privProtectFunc(String s)
{
System.out.println("BaseClass.privProtectFunc() " + s);
}
// This should behave the same as private protected
protected private void protectPrivFunc(String s)
{
System.out.println("BaseClass.protectPrivFunc() " + s);
}
}
class DerivedClass extends BaseClass
{
public void func(String s)
{
// both of these two function calls should work
super.privProtectFunc("DerivedClass.func() " + s);
super.protectPrivFunc("DerivedClass.func() " + s);
}
}
compile, you receive compiler error message:
No method matching (function signature) found in (base class).
Steps to reproduce
Compile the following code
/* Access modifier tests
* This tests same package access modifiers for member functions
*/
class AccessTest
{
public static void main(String args[])
{
//
BaseClass baseClass = new BaseClass();
baseClass.func("Kevin");
// this should be okay
baseClass.protectFunc("Arthur");
// this should generate a compiler error
// baseClass.privFunc("Frank");
// this should generate a compiler error
// baseClass.privProtectFunc("Jim");
// now lets try this with a derived class
DerivedClass derivedClass = new DerivedClass();
derivedClass.func("Eric");
}
}
class BaseClass
{
public void func(String s)
{
System.out.println("BaseClass.func() " + s);
}
protected void protectFunc(String s)
{
System.out.println("BaseClass.protectFunc() " + s);
}
private void privFunc(String s)
{
System.out.println("BaseClass.privFunc() " + s);
}
// this syntax should limit other functions in the default
// package from calling this function, but allow
// derived classes to call it.
private protected void privProtectFunc(String s)
{
System.out.println("BaseClass.privProtectFunc() " + s);
}
// This should behave the same as private protected
protected private void protectPrivFunc(String s)
{
System.out.println("BaseClass.protectPrivFunc() " + s);
}
}
class DerivedClass extends BaseClass
{
public void func(String s)
{
// both of these two function calls should work
super.privProtectFunc("DerivedClass.func() " + s);
super.protectPrivFunc("DerivedClass.func() " + s);
}
}