3i Infotech Papers: Sample Questions 1027 - 1029 of 1245

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

Question number: 1027

» Languages » Java

Essay Question▾

Describe in Detail

What are abstract class?

Explanation

Understanding of abstract class.

Understanding of Abstract Class.

Understanding of abstract class.

  • A class that is declared with abstract keyword, is known as abstract class.

  • They are called interfaces.

  • It can abstract and non-abstract methods.

  • We cannot instantiate them, and they contain methods declared with or without an implementation.

  • In interfaces, all fields are automatically public, static and final and all methods are public.

Question number: 1028

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is function overloading and operator overloading?

Explanation

Define parts of compile tme polymorphism

Define Parts of Compile Tme Polymorphism

Define parts of compile tme polymorphism

Function Overloading:

  • Function overloading means that functions with same name can be defined with different parameters or different number of parameters.

  • Appropriate function is identified by the compiler by number or types of parameters.

  • Reduces the investment of different function names and used to perform similar functionality by more than one function.

Operator Overloading:

  • Operator overloading allows operators on user defined objects.

  • All overloaded operators provides syntactic sugar for function calls that are equivalent.

  • Without fundamental language changes, operator overloading provides a pleasant facade.

Question number: 1029

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Which is the only operator in C ++ which can be overloaded but NOT inherited.

Explanation

  • The “=” (equal) operator can be overloaded but cannot be inherited.

  • Example:

#include < iostream > #include < iomanip > using namespace std; class A {public: int _i; A (int i): _i (i) {} virtual A &operator= (A const &other) {if (this! =&other) {_i = other. _i; } return * this; } virtual A operator+ (A const &rvalue) {return A (_i + rvalue. _i); } virtual void print () {cout < < “A (_i=” < < _i < < “) “; } }; class B: public A {public: int _j; B (int i, int j): A (i), _j (j) {} virtual void print () {cout < < “B (_i=” < < _i < < “, _j=” < < _j < < “) “; } }; int main () {A a1 (5), a2 (3); a1. print (); cout < < ” + “; a2. print (); cout < < ” = “; A a3 = a1 + a2; a3. print (); cout < < endl; B b1 (5,3), b2 (3,5); b1. print (); cout < < ” + “; b2. print (); cout < < ” = “; // this works, although (b1 + b2) returns an A since it uses A’s operator+ (b1 + b2). print (); // this does not work: no conversion from A to B, i. e. operator = not inherited // B b3 = b1 + b2; // b3. print (); cout < < endl; return 0; }

Answer:

A (_i = 5) + A (_i = 3) = A (_i = 8)

B (_i = 5, _j = 3) + B (_i = 3, _j = 5) = A (_i = 8)