3i Infotech Papers: Sample Questions 1229 - 1231 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 1229

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Write a program which employs Recursion.

Explanation

  1. #include<iostream>
  2. using namespace std;
  3. int fact(int n)
  4. {
  5.     if (n == 0)
  6.     return 1;
  7.     n=n*fact(n-1);
  8.     return n;
  9. }
  10. int main() {
  11.     int n=5;
  12.     cout << "Factorial of number " << n << " is : " << fact(n) << endl;
  13.     return 0;
  14. }

Question number: 1230

» Languages » Java

Short Answer Question▾

Write in Short

Size of operator is executed during________

Explanation

  • Size of is a used operator in the C programming language.

  • It is a compile time unary operator which can be used to compute the sizeof its operand.

  • The result of sizeof is of unsigned integral type which is usually denoted by size_t.

  • Size of can be applied to any data-type, including primitive types as an integer and floating-point types, pointer types.

Question number: 1231

» Languages » Java

Essay Question▾

Describe in Detail

What are the advantages of inheritance?

Explanation

  • Reusability of code and accessibility of variables and methods of the superclass by subclasses.

  • The most frequent use of inheritance is for deriving classes using existing classes, which provides reusability.

  • Reusability –

    • Facility to use public methods of base class without rewriting the same.

  • Extensibility –

    • Extending the base class logic in derived class.

  • Data hiding –

    • Base class can keep some data private to prevent alteration by derived class

  • Overriding –

    • Inheritance can override methods of the base class so meaningful implementation can be designed in the derived class.