How to make some functions of a class as private for third level of inheritance.

Posted by Shantanu Gupta on Stack Overflow See other posts from Stack Overflow or by Shantanu Gupta
Published on 2010-05-17T04:57:38Z Indexed on 2010/05/17 5:10 UTC
Read the original article Hit count: 260

Filed under:
|
|
|
|

I have created a class say A which has some functions defined as protected.

Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor.

I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functions only not all the functions and class C is inheriting class B.

How can I restrict access to some of the functions of Class A from Class C ?

 Class A
    {
    private A(){}
    protected A(int ){}
    protected calc(){}
    protected allow(){}
    }

    Class B : A
    {} // calc() and allow() should be accessible here 
    CLass C:B
    {
     // calc() should not be accessible here but allow() should be accessible here.
    }

© Stack Overflow or respective owner

Related posts about oop

Related posts about classes