Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 25 - 26 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 25

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is class invariant?

Explanation

  • A class invariant is a condition that should be true in all valid states for an object.
  • It is a logical condition to ensure the correct working of a class.
  • Class invariants must hold when an object is created, and they must be preserved under all operations of the class.
  • In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.
  • Example: suppose we want to ensure that all point objects x and y coordinates are never negative.
  • We must ensure that a client cannot construct a point object with a negative x or y value.
  • We must ensure that a client cannot move an existing point object to a negative (x , y) location.
The Class Invariant

Question 26

C & C Plus Plus
Edit

Describe in Detail

Essay▾

How is exception handling carried out in C ++ ?

Explanation

Understanding of Throwable Parts
  • Exception handling is done using catch block and throw statement.
  • Try includes code, which result in exception.
  • One or more catch enclose the try “catch” the exception starting from most specific to least specific.
  • Function can declare a throw (… .) declaration stating that it does not handle exceptions of the specified types.
  • Such exceptions are then thrown to the calling function.
  • If an exception remains unhandled program will have abnormal termination.
  • Try catch blocks can be nested any level.

Developed by: