(Q) Why C++ is called object oriented programming language?
(A) Because C++ supports OOPs features
eg: Data encapsulation, data hiding, data abstraction, inheritance, polymorphism, exception handling, message passing.
(Q) Difference between method overloading and method overriding in C++?
(A) Overloading is a function or method performing additional task in addition to the normal task. i.e Same function handles more than one task.
Overriding is a method is rewritten in the base class. In this is done using inheritance.
(Q) What type of method can be overridden in C++?
(A) In C++ methods with access specifier public can be overridden.
(Q) Write a program to illustrate method overriding in C++?
(A)
#include<iostream.h>
Void sum();
Void sum(int);
Void sum(float);
Void sum(int, float);
Void main(){
Int f,s;
Float f1,f2;
clrscr();
cout<<”Enter any 2 intergers:”;
cin>>f>>s;
cout<<”Enter any two float numbers;”;
cin>>f1>>f2;
sum();
sum(f);
sum(f,s);
sum(f1,f2);
}
Void sum(){
Int x,y;
Cout<<”Enter any 2 no:”;
Cin>>x>> y;
Cout<<”Sum vlue=”<<x+y<<endl;
}
Void sum(int x){
Cout<<”Sum vlue=”<<x+x<<endl;
}
}//same way you can add other methods
(Q) Difference between an object and a class?
(A) Class is a collection of data members and methods. Object is an instance of a class. In brief object is a memory space where all the data members and member functions will be loaded.
(Q) What is memory leaking in C++ ?
(A) A memory leak is the situation that occurs when dynamically allocation is used u\without handling properly.
(Q) What are the things contains in .obj file ?
(A) When a C++ program is compiled, the program will be executed and an object file is created which contains all data and suitable linking files in machine understandable language.
(Q) In C++ have a default constructor?
(A) Yes, compiler creates the default constructor only and only if the class doesn’t contain any constructor.
(Q) What is inline function in C++?
(A) Inline is a new topic in C++, When we initialize a function inline and call it in main() then instead of moving the control from calling function to called function, the function body will include at the function calling. Main purpose of Inline function is to improve the program performance. It is recommended not to use inline with long code programs.
(Q) What is Dynamic memory allocation?
(A) int m[10]={1,2,3,4};
In the above example occupied memory is 10*2 = 20 bytes but actually we are using only 4*2 = 8 bytes so 12 bytes of memory is wasted. To stop this wastage of memory we use dynamic memory allocation concept. This will dynamically allocate the memory to the space we used.
Syntax for Dynamic memory allocation: <pointer variable>=new <data type> [size of array];
(Q) What is friend function in C++?
(A) In C++ by default private data can assess only by members of that class but it is not possible to access outside the class functions. This is possible by friend function.
friend function mean it is not a member of that class but can access private data of the class. Just you need to add friend in front of method.
(Q) Which has more priority (.) or (*)?
(A) Dot(.) operator has more priority than asterisk (*). Using brackets we can implicitly apply * for operands when needed.