State and describe visibility modes used in inheritance with their effects.

1 Answer

Answer :

Visibility modes:

private

protected

public

image

Private:

o When a base class is privately inherited by a derived class, „public

members‟ and „protected members‟ of the base class become

„private members‟ of the derived class.

o Therefore, the public and protected members of the base class can

only be accessed by the member functions of derived class but,

cannot be accessed by the objects of the derived class.

Syntax:

class derived: private base

{

//Members of derived class;

};

Public:

o When a base class is publicly inherited by a derived class then „protected members‟ of base class becomes „protected members‟

and ‟public members‟ of the base class become „public members‟

of the derived class.

o Therefore the public members of the base class can be accessed

by both the member functions of derived class as well as the

objects of the derived class.

Syntax:

class derived: public base

{

//Members of derived class;

};

Protected:

o When a base class is protectedly inherited by a derived class,

„public and protected members‟ of the base class become

„protected members‟ of the derived class.

o Therefore the public and protected members of the base class can

be accessed by the member functions of derived class as well as

the member functions of immediate derived class of it but they

cannot be accessed by the objects of derived class

Syntax:

class derived: protected base

{

//Members of derived class;

};

Related questions

Description : What is inheritance and explain visibility modes in detail.

Last Answer : Inheritance: The mechanism of deriving new class from an old (existing) class is called as inheritance. With inheritance, one class acquires the properties of objects of other classes. ... members of derived class and public members of base class becomes public members of derived class.

Description : Explain different visibility modes and its effect in inheritance.

Last Answer : Different visibility modes are: 1) Private 2) Protected 3) Public Effect in inheritance: Private members of base class are not inherited directly in any ... become protected members of derived class and public members of base class become public members of derived class

Description : List various visibility modes used in inheritance.

Last Answer : Different visibility modes used in inheritance are: 1) Private 2) Protected 3) Public 

Description : State and describe visibility modes and its effects used in inheritance.

Last Answer : Different visibility modes are: 1. Private 2. Protected 3. Public Effects of visibility modes in inheritance:  Private members of base class are not inherited directly in any ... members of derived class and public members of base class become public members of derived class.

Description : State and describe types of inheritance.

Last Answer : Types of inheritance: o Single Inheritance o Multiple Inheritance o Multilevel Inheritance. o Hierarchical Inheritance o Hybrid Inheritance Single Inheritance o The mechanism of deriving a new class from existing single ... : public B, public C { // class D body; };

Description : With example, describe multiple inheritance. 

Last Answer : A derived class with multiple base classes is called as multiple inheritance. A derived class inherits properties of all the base classes. It also can have its own properties. Syntax:- class base _class _name1 { ____ } ... clrscr(); derived d; d.get2(); d.put2(); getch(); }

Description : What is multiple inheritance? What is multilevel inheritance? What is difference between them?

Last Answer : Multiple Inheritance: When A derived class is derived from more than one base class then it is known as multiple inheritance. A derived class can inherit the attributes of all base classes ... , last derived class will inherit only public property of all class including intermediate class.

Description : Write a program for multiple inheritance. 

Last Answer : #include #include class base1 { public: void show1() { cout

Description : Explain the following with syntactic rules: (i) public inheritance (ii) protected inheritance.

Last Answer : (i) public inheritance: i) When the visibility-mode is public the base class is publicly inherited. ii) In public inheritance, the public members of the base class become public members of the derived class and ... variables; Member function; }; class B : protected A { Members of class B };

Description : Write a program to implement single inheritance. Declare base class employee with Emp_No. and Emp_Name. Declare derived class fitness with height and weight. Accept and display data for one employee.

Last Answer : #include<iostream.h> #include<conio.h> class employee { protected: int emp_no; char emp_name[10]; public: void gete() { cout<< enter employee details ; cin>>emp_no; cin>> ... f.gete(); f.pute(); f.getft(); f.putft(); getch(); }

Description : Explain hybrid inheritance with example.

Last Answer : Hybrid inheritance is also referred as mixed inheritances. As the name suggests it is a combination of all the kinds of inheritance mechanisms, namely single inheritance, multiple inheritance, multilevel inheritance and hierarchical inheritance. ... { D d; d.getdata(); d.putdata(); }  

Description : Implement single inheritance for following fig. Accept and display data for 1 table.

Last Answer : #include class furniture { protected: char material[20]; int price; }; class table :public furniture { int height ; float sur_area; public: void getdata() { coutmaterial; coutprice; coutheight; coutsur_area; } void putdata() { cout

Description : List different types of inheritance with suitable diagram.

Last Answer : Types of inheritance: 1) Single inheritance: A derived class is derived from only one base class. Diagram: 2) Multiple inheritance: A derived class is derived from more ... ) Hybrid inheritance: Combination of single, multiple, multilevel and hierarchical inheritance.  Diagram:

Description : Write any two advantages of inheritance.

Last Answer : Advantages of inheritance: 1) Use of inheritance in a program gives reusability of code. 2) Inheritance avoids duplication of code in program. 3) Inheritance reduces length of code. 4) Inheritance reduces time to compile the lengthy code by reusing it. 

Description : Explain single inheritance with suitable example.

Last Answer : When a single derived class is derived from only one base class then it is called as single inheritance. In a single inheritance, derived class can inherit some or all members of base class. It is implemented by specifying ... s; clrscr(); s.getdata(); s.putdata(); getch(); }

Description : Define multiple inheritance. Give example.

Last Answer : Multiple Inheritance: When a single class is derived from more than one base class then it is known as multiple inheritance. A derived class can inherit the attributes of all base classes from which it ... derived class derived from two base classes base class Test and base class Sports .  

Description : Write a program in C++ to implement single inheritance from following figure:

Last Answer : #include<iostream.h> #include<conio.h> class product { protected: int prodid; char prodname[20]; }; class edible:public product { char flavour[20]; public: void accept() { cout<< ... for(i=0;i<5;i++) { e[i].display(); } getch(); }

Description : Write a program in C++ to implement following inheritance. Assume suitable data.

Last Answer : #include<iostream.h> #include<conio.h> class employee { int empid; char empname[20]; public: void accept() { cout<<"\n enter empid, empname:"<<endl; cin>>empid>> ... m.acc1(); m.dis1(); w.acc2(); w.dis2(); getch(); }

Description : State and describe use of pointer operator and address operator. Give one example of each. 

Last Answer : Pointer operator:- * It is used to declare a pointer variable. Also used as "value at" operator to read value stored inside the address pointed by pointer. Example: int *ptr; Address operator:-& ... address of a variable can be stored in pointer variable. Example: int a,*ptr; ptr=&a;

Description : State and describe access specifiers used inside class to declare members.

Last Answer : Access specifiers: 1. private 2. protected 3. public Private access specifier: Class members declared as private can be accessed only from within the class. Outside class access is not allowed for private members of ... { private: int a; protected: int b; public: void display() { cout

Description : Describe multiple constructor by giving example.

Last Answer : Multiple constructor: Multiple constructors is a category of constructor in which a class can have more than one constructor. This is also known as constructor overloading. All constructors are defined with the same name as the class ... constructor 1 integer(int a, int b) { m = a; n = b; cout

Description : Describe constructor with syntax and example.

Last Answer : A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever an object of its associated class ... )//constructor declaration { a=0; } }; void main() { ABC x; }

Description : Describe with example the use of insertion and extraction operators.

Last Answer : Insertion operator: The operator "" is called as extraction operator or get from extracts the value from keyboard and assigns it to the variable on its right. Extraction operator is used with cin statement to accept input from user (keyboard). Example: cin>>number1; 

Description : Describe pointer to object with an example. 

Last Answer : When address of an object of a class is stored into the pointer variable of the same class type then it is pointer to object. This pointer can be used to access the data member and member functions of same class. ... (); // Invoking getdata()using pointer to object p1. ptr->display(); }

Description : Describe structure of C++ program.

Last Answer : General C++ program has following structure. INCLUDE HEADER FILES DECLARE CLASS DEFINE MEMBER FUNCTIONS DEFINE MAIN FUNCTION Description:-  1. Include header files In this section ... Functions This section the programmer creates object and call various functions writer within various class.

Description : Describe syntax and use of defining member function outside class. Give one example.

Last Answer : Member function that is declared inside a class has to be defined separately outside the class. These member functions associate a membership identify label in the header. This label tells the ... ) A member function can call another member function directly, without using the dot operator. 

Description : With suitable example, describe use of this pointer.

Last Answer : 1. C++ uses a unique keyword called this to represent an object that invokes a member function. 2. This unique pointer is automatically passed to a member function when it is invoked. 3. this is a pointer that always ... ; public: void setdata(int x) { this ->a=x; } void putdata() { cout

Description : Describe with example importance of virtual base class.

Last Answer : A virtual base class (Grandparent class) is a class that avoids duplication of inherited data in derived class (child class) derived from parent classes (parent1 and parent2) which in turn derived ... duplications class L is declare as virtual base class while defining base classes B1 and B. 

Description : With example, describe use of scope resolution operator.

Last Answer : In C, the global version of a variable cannot be accessed from within the inner block. C++ resolves this problem by introducing a new operator:: called scope resolution operator. This can be used to uncover a hidden variable. It takes ... cout << ::m = <<::m; } return 0; }

Description : With example, describe use of static member function.

Last Answer : A static member function can have access to only other static members (functions or variables) declared in the same class. A static member function can be called using the class name as follows: class_name:: ... static void showcount()----------------//static member function { cout

Description : With suitable example, describe use of virtual function in polymorphism.

Last Answer : In order to achieve polymorphism, objects belonging to different classes should be able to respond to the same message at different instances which initiates the use of single pointer variable to refer to objects of ... void accept() { coutroll; coutname; } virtual void display() { cout

Description : Describe the concept of constructor with default argument with suitable example.

Last Answer : Definition: The constructor where we can assign default values for one or more parameters at the time of function declaration is called as constructor with default argument Example: class complex ... and 3.0 to img., because the actual parameters, when specified overrides the default value.

Description : State characteristic of static data member. Explain why static data member must be defined outside the class. 

Last Answer : Characteristics of static data members: 1. It is initialized to zero when the first object of its class is created. No other initialization is permitted. 2. Only one copy of that member is created ... member(s) it is necessary to make static members global and re-declared outside of the class.

Description : State any four object oriented programming language.

Last Answer : Object oriented programming language: C++ Smalltalk Object pascal java Simula Ada Turbo pascal Eiffel C# Python

Description : Implement a program to declare a class city with data members city name and state. Accept and display data for 1 object using pointer to object.

Last Answer : #include<iostream.h> #include<conio.h> class city { char city_name[20],state[20]; public: void accept() { cout<<"\nEnter city data:"; cout<<"\nName:"; ... ); ptr=&c; ptr->accept(); ptr->display(); getch(); }

Description : Define constructor. State any two types of constructor.

Last Answer : Definition: A constructor is a special member function whose task is to initialize the objects of its class. Types of constructor: 1) Default constructor 2) Parameterized constructor 3) Copy Constructor 4) Constructor with default value 5) Multiple constructor/overloaded constructor

Description : State any two access specifier with example.

Last Answer : Access specifier: 1. private: 2. protected: 3. public Example: class sample { private: int a; protected: int b; public: void display() { cout

Description : State the concepts of object oriented programming.

Last Answer : Basic Concepts of Object Oriented Programming:  1. Objects  Objects are the basic run time entities in an object-oriented system. They may represent a person, a place, a ... objects that communicate with each other. Objects communicate with one another by sending and receiving information.

Description : State any four rules for operator overloading.

Last Answer : Rules for operator overloading: 1. Only existing operators can be overloaded. New operators cannot be created. 2. The overloaded operator must have at least one operand that is of user defined type. 3. ... * and / must explicitly return a value. They must not attempt to change their own arguments. 

Description : State any four characteristics of friend function.

Last Answer : Characteristics of friend function: 1. It is not in the scope of the class to which it has been declared as friend. 2. As it is not in the scope of the class, it cannot be called using the ... public or the private part of a class without affecting its meaning. 6. It has the objects as arguments.

Description : State two advantages of pointer.

Last Answer : Advantages of pointer: Pointers save the memory. Pointers reduce the length and complexity of a program. Pointers allow passing of arrays and strings to functions more efficiently. Pointers make possible to return more than one value from the function. Pointers increase the processing speed.

Description : State any four types of constructor.

Last Answer : Types of constructor: Default constructor Parameterized Constructor Constructor with Default Argument Copy Constructor Multiple/overloaded constructor

Description : State any four applications of OPP.

Last Answer : Applications of OOP: Real time systems Simulation and modeling Object-oriented databases Hypertext, hypermedia and expert Ext AI and expert systems Neural networks and parallel programming Decision support and office automation systems CIM/CAM/CAD systems

Description : Write a program in C++ to declare a class measure having data members as add 1, add 2, add 3. Initialize the values of two data members using constructor and display their addition using function.

Last Answer : #include<iostream.h> #include<conio.h> class measure { public: int add1,add2,add3; measure(int a,int b) { add1=a; add2=b; } void cal() { add3=add1+add2; } void display() ... ;>a>>b; measure m1(a, b); m1.cal(); m1.display(); getch(); }

Description : Write a program which concate and reverse string by using pointer to string.

Last Answer : #include #include void main()  { char str1[20], str2[20], rev[20],*p1,*p2; int cnt=0; clrscr(); coutstr2;  p1=&str1[0];  p2=&str2[0]; while(*p1!='\0')  { p1++;  } while(*p2!='\0')  { *p1=*p2; p1++; p2++;  }  *p1='\0'; cout

Description : What is constructor? How user can declared constructor in derived class? Explain with example.

Last Answer : Constructor:- Constructor is a special member function which has same name as a class name and is used to initialize object during compile time of program. Declaring constructor in derived class If a base class contains a ... derived d(2,5); d.displaybase(); d.display(); getch(); }

Description : What is function? What is call by value? What is call by reference? What is the difference between them?

Last Answer : Function: A function is a group/set of statements/instruction that performs a specific task. It can be system defined i.e. clrscr(), getch(), or user defined i.e. add(), sub(). ... reflected inside as well as outside the function. Difference between Call by Value and Call by Reference:

Description : What is polymorphism? Enlist different types of polymorphism. What are the differences between them?

Last Answer : Polymorphism: It is a feature of object oriented programming which allows a programmer to have a more than one function having same name but different /same parameters but performs different/ ... Compile Time polymorphism o Virtual Function Difference between Types of Polymorphism:

Description : Write a program which perform arithmetic operation using pointer.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int num[5]={56,75,22,18,90}; int ptr; int i; cout<< array elements are:: ; for(i=0;i<5;i++) ptr=num; cout<< ... 3; cout<< value of ptr+=3:: <<*ptr; cout<< \n ; getch(); }

Description : How to define virtual function? Give example.

Last Answer : A virtual function is a member function that is declared within a base class and redefined by a derived class. To define virtual function following syntax is used: Class baseclass { virtual function_name() { } ... } }; Example: #include class Base { public: virtual void show( ) { cout