Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 163 - 164 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 163

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is encapsulation?

Explanation

Understanding of Encapsulations
  • A process of wrapping of data and methods in a single unit- “object” is called encapsulation.
  • Thus, state and behaviour are now in a single container.
  • Encapsulation is done using class keyword-
    • State is represented by declaration of variables on attributes
    • Behaviour is represented by operations in terms of methods

Advantage of Encapsulation:

  • Encapsulation secures data from other methods- data is available only within the class not accessible outside the class.
  • Data inside the class can only be manipulated by functions in the class

Benefit of Encapsulation:

  • Provides abstraction between an object and its clients.
  • Protects an object from unwanted access by clients.
  • Example: A bank application forbids a client to change an account՚s balance.

Question 164

C & C Plus Plus
Edit

Write in Short

Short Answer▾
  1. main ()
  2. {
  3.     inti =-1, j =-1, k =0, l =2, m;
  4.     m =i ++ &&j ++ &&k ++|l ++;
  5.     printf ( “%d %d %d %d %d” i, j, k, l, m);
  6. }

Explanation

  • Logical operations always give a result of 1 or 0.
  • Logical AND (&&) operator has higher priority over the logical OR (|) operator.
    Table Shows the Program
    i ++ && j ++ && k ++The result of this expression is 0

    (-1 &&-1 && 0 = 0)

    0|2The result is 1 (because OR operator always gives 1 except for 0|0՚ combination-for which it gives 0)
  • So the value of m is 1.
  • The values of other variables are also incremented by 1.
  • Than all variable value increase and print the 00131

Developed by: