Base class has two public data members. How can i derive a
new class with one datamember as public and another data
member as private?.
Answer Posted / iyappan
just have a look on the given program. Then you can get
idea about it.
class base
{
public:
virtual void fun1(){printf("I am base class public
fun1");}
virtual void fun2(){printf("I am base class public
fun2");}
};
class derived:public base
{
void fun1(){printf("I am derived class private
fun1");}
public:
void fun2(){printf("I am derived class public
fun2");}
};
int main()
{
derived obj;
obj.fun1();//it will show compile time error.
because this is private member of derived class
obj.fun2();//it will work fine.
base *ptr = &obj;
ptr->fun1();//it will work fine.
ptr->fun2();//it will work fine.
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
What is difference between polymorphism and inheritance?
can we make game by using c
What is the renewal class?
What is the main feature of oop?
Can we create object of interface?
What is this pointer in oop?
What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?
What is oops and its features?
Can destructor be overloaded?
How oops is better than procedural?
Which is not an object oriented programming language?
Why do we use oop?
how to get the oracle certification? send me the answer
How do you define a class in oop?
Give two or more real cenario of virtual function and vertual object