Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

About calling private methods of super class

Former Member
0 Kudos

Hi .

class is derived from one class and i will made that as friend to derived class then we can access the private elements of super class in sub class wright.

how to do ?.

regards.

2 REPLIES 2

Former Member
0 Kudos

take Eg Class A (the class containing private method 'M')

class B (from which you want to access class A's private method)

For this you have to declare B as friend from A remember not visa viz..

so you have to edit the sure class. dont forget to create a ref variable and the object of the class A.

Former Member
0 Kudos

Hi

<b>Synatx and Visisbilty</b>

1)the public and protected components of the super class are visible in the subclass

2)private section of the super class is not visible in the sub classes

3)private components of the sub class can have same name as the private component of the super class

4) public and protected components of the sub class can not have the same name as that have been used in super class

<b>Synatx</b>

CLASS SUPER_CLAS DEFINATION

PUBLIC SECTION.

PUBLIC COMPONENTS

PROTECTED SECTION

PROTECTED COMPONETS

PRIVATE SECTION

PRIVATE COMPONENTS

ENDCLASS

CLASS SUB_CLASS DEFINATION INHERITING FROM SUPER_CLASS

PUBLIC SECTION.

PUBLIC COMPONENTS

PUBLIC COMPONENTS (SUPER_CLASS)

PROTECTED SECTION

PROTECTED COMPONETS

PROTECTED COMPONENTS (SUPER CLASS)

PRIVATE SECTION

PRIVATE COMPONENTS

ENDCLASS.

<b>friend class</b>

CLASS C1 DEFINITION FRIENDS OBJ1 .. OBJN

CLASS C1 DEFINITION LOCAL FRIENDS OBJ1..OBJN

CLASS C1 DEFINITION GLOBAL FRIENDS OBJ1..OBJN

with the friend relationship one class can grant another class or interface (and all clases that implement that interface ) acess to its PROTECTED AND PRIVATE COMPONENTS

friendship is one sided class c1 granting feindship to class c2 does not mean c1 is a friend of c2 unless c2 explicitly grants c1 as friend

subclasses of friend and interfaces that receives a friend as a component interface

become friend

a friend of a super class is not automatically friend of itssub class

<b>Reward if useful</b>