Set - 3

Question 16 :

What methods can be overridden in Java?

Answer :

In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.

Question 17 :

What are the defining traits of an object-oriented language? 

Answer :

The defining traits of an object-oriented langauge are:
* encapsulation
* inheritance
* polymorphism

Question 18 :

What is the need for a Virtual Destructor ? 

Answer :

Destructors are declared as virtual because if do not declare it as virtual the base class destructor will be called before the derived class destructor and that will lead to memory leak because derived class’s objects will not get freed.Destructors are declared virtual so as to bind objects to the methods at runtime so that appropriate destructor is called.

Question 19 :

Differences of C and C++
Could you write a small program that will compile in C but not in C++ ? 

Answer :

In C, if you can a const variable e.g. 
const int i = 2; 
you can use this variable in other module as follows 
extern const int i; 
C compiler will not complain. 

But for C++ compiler u must write 
extern const int i = 2; 
else error would be generated.

Question 20 :

Bitwise Operations - Given inputs X, Y, Z and operations | and & (meaning bitwise OR and AND, respectively), what is output equal to in? 

Answer :

output = 

(X & Y) | (X & Z) | (Y & Z);