State a runtime polymorphism example program in C++

Answer includes runtime polymorphism example program in C++ OOPs and about virtual and pure virtual function in C++. Example of run time polymorphism in C++ object oriented programming is function overriding where functions get resolved at run time i.e. when we execute the application. This is different than compile time polymorphism where function gets resolved … Read more State a runtime polymorphism example program in C++

Print numbers from 1 to 100 without using loops in C++ code

Logic is simple to print numbers from 1 to 100 without using loops in C++ code. Note that recursion and goto statements are also not allowed. Logic: Create a class, let’s say Number, create a static data member variable called num and initialize it with 1. In class constructor print number and increment variable num … Read more Print numbers from 1 to 100 without using loops in C++ code

What is default constructor in C++? – Availability Discussion

Default constructor in C++ is provided by the compiler if we don’t implement any constructor in the class. For example, in below class, we don’t have any constructor implemented. Hence, once we create an object of the class then default constructor is called in C++ program provided by the compiler internally. class A{ public: void … Read more What is default constructor in C++? – Availability Discussion

Can static function access non static variables in C++?

No, Static function of a class in C++ cannot access non-static variables, but, it can access static variable only. However, non-static member function can access static and non-static variable both. Static function is not associated with class object, means without object using class name only it can be called. whereas non-static variables are associated with … Read more Can static function access non static variables in C++?

Which is called first constructor or overloaded new operator in C++?

Interview Question: A C++ class has constructor and overloaded new and delete operator function. If we create a class object dynamically using new then out of constructor and overloaded new operator function, which one get called first? Recommended to read a simple program with important important points of new and delete operator overloading in C++ … Read more Which is called first constructor or overloaded new operator in C++?

Is C++ Empty Constructor necessary to write in a class?

Answer: C++ Empty constructor necessity  depends upon class design requirements. We know that C++ class constructor is called when we create an object of a class. If a class is not required to initialize its data member or does not contain data member, there is no need to write empty constructor explicitly. On class object … Read more Is C++ Empty Constructor necessary to write in a class?

What is constructor in C++ Programming and its purpose?

Answer: Constructor in C++  programming of a class is like a member function of a class that have same name as the class name. For example, in below class Animal, constructor name will also be Animal (). class Car { public: //Constructor Car(){ } }; The main purpose of the class constructor in C++ programming … Read more What is constructor in C++ Programming and its purpose?

What is constructor overloading in C++ – Short and Easy

Constructor overloading in C++ programming is same as function overloading. When we create more that one constructors in a class with different number of parameters or different types of parameters or different order of parameters, it is called as constructor overloading. In sample words, writing multiple constructors in a class is known as constructor overloading … Read more What is constructor overloading in C++ – Short and Easy

Describe constant member function in C++ with Example

Answer: Constant member function in C++ of a class is the function that prevents modification of any member data of a class in C++ program. To make a function constant in a class, we use “const” keyword in function declaration. For example, “void foo() const ” . In below source code example, we have declare … Read more Describe constant member function in C++ with Example