How to define a derived class, C/C++ Programming

Assignment Help:

How to define a derived class ?

A singly inherited derived class id defined by writing :

  • The keyword class.
  • The name of the derived class .
  • A single colon (:).
  • The type of derivation ( private , protected, or public ).
  • The name of the base, or parent class.
  • The remainder of the class definition.

e.g.

                class A

                 {

                  public :

                                                int public_A;

                                                void public_function_A();                           

  private :

                                                int pri_A;

                                                void private_function_A();

  protected :

                                                int protected_A;

                                                void protected_function_A();

 

  };

 

class B : private  A

 {

                  public :

                                                int public_B;

                                                void public_function_B();                            

       private :

                                                int pri_B;

                                                void private_function_B();

};

class C : public  A

 {

  public :

                                                int public_C;

                                                void public_function_C();                            

        private :

                                                int pri_C;

                                                void private_function_C();

 };

class D : protected A

 {

                  public :

                                                int public_D;

                                                void public_function_D();                                

                  private :

                                                int pri_D;

                                                void private_function_D();

                 };

A derived class always have all of the member members from its base class. You cannot "subtract" anything from a base class. Though, accessing the inherited variables is a dissimilar matter. It is also important to understand the privileges that the derived class has insofar as access to members of its base class are concerned. In other words, just because you happen to derive a class does not mean that you are automatically granted complete and unlimited access privileges to the members of the base class. to understand this you must look at the dissimilar types of derivation and the effect of each one.

 


Related Discussions:- How to define a derived class

Write in a file - c program, Write in a file: void main() { int ...

Write in a file: void main() { int i,j,k,l,list[1000]; FILE *fp; char any[8];   cout cin >> any;   fp = fopen(any,"wb");     for(j=0;j     {

Super ansii prgm, Ask quIn the Byteland country a string "s" is said to sup...

Ask quIn the Byteland country a string "s" is said to super ascii string if and only if count of each charecter in the string is equal to its ascci value in the byteland country as

Write program.., # Dear I want help to programmer that write C++ code for...

# Dear I want help to programmer that write C++ code for my small project as soon as posible If we can help me?..

Explain the symbolic constants in c language, Explain the Symbolic Constant...

Explain the Symbolic Constants in c language? Symbolic constants are the constants of any type that declared by using the #define compiler directive and it is a preprocessor di

C program to convert number to binary, Write a program in C that you will n...

Write a program in C that you will name "divide.exe", to divide one 32-bit twos-complement binary number by another, giving the quotient and the remainder, using the subtract-shift

Recursive function, Write a recursive function recursiveMin that takes an i...

Write a recursive function recursiveMin that takes an integer array, a starting subscript and an ending subscript as arguments, and returns the smallest element in the array. The

Described the order that objects in an array is destructed?, Described the ...

Described the order that objects in an array is destructed?

How can one "reopen" std::cin & std::cout in binary mode?, A: It is impleme...

A: It is implementation dependent. Verify with your compiler's documentation. For instance, assume you wish to do binary I/O using std::cin & std::cout. Unluckily there is no st

Write a program to illustrate passing structure to function, Write a Progra...

Write a Program to illustrate passing structure to function? # include struct customer { int id; char name[15]; }; void func_struct(struct customer); main() { struct c

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd