TECHNICAL INTERVIEW QUESTIONS AND ANSWER 6 TO 10
Inheritance
is a mechanism in which new class is derived from the existing class. Existing
class is called as a super class or parent class or base class. New class which
is derived is called as a sub class or child class or derived class. This
inheritance will also inherits the properties of base class.
7.TYPES OF INHERITANCE:
Single Inheritance
Multiple Inheritance
Multi-Level Inheritance
Hierarchical Inheritance
Hybrid Inheritance (also known as Virtual
Inheritance)
8.DEMONSTRATION OF INHERITANCE:
IN CPP:
#include<stdio.h>
#include<conio.h>
class Vehicle
{
public:
Vehicle()
{ cout<<”\n This is a vehicle” };
};
Class Car : public Vehicle {};
int main()
{
Car obj;
return 0;
}
Output : This is a vehicle
9.LOOPS:
Loop
executes a set of statements for a predetermined number of times. There are 2
types of loops namely Entry Controlled Loop and Exit Controlled Loop.
10.CLASS VS INTERFACE:
No
|
CLASS
|
INTERFACE
|
1.
|
Supports only multilevel and
hierarchical inheritance but not multiple inheritance,
|
Supports all types of
inheritance including multiple inheritance.
|
2.
|
“extends” keyword is used to inherit.
|
“implements” keyword is used to inherit.
|
3.
|
Methods can be final and
static.
|
Methods should not be final and
static.
|
4.
|
Variables can be private.
|
Variables should be public only.
|
5.
|
Can have constructors.
|
Cannot have constructors.
|

Comments
Post a Comment