Languages [TCS Placement]: Sample Questions 125 - 126 of 131

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 125

Edit

Describe in Detail

Essay▾

What are the advantages and disadvantages of a heap?

Explanation

  • Advantages:
  • Storing data on the heap is slower than stack but main advantage is flexibility.
  • Memory can be allocated and removed in any particular order.
  • Garbage Collection runs on the heap memory to free the memory used by objects that don՚t have any reference.
  • Any object in the heap space has global access and can be referenced from anywhere of the application.
  • Memory on stack can be accessed only by the called function
  • Disadvantages:
  • Heap is slower than stack .
  • Slowness in the heap can be compensated if an algorithm is well designed and implemented.
  • Memory management is more complex in heap because it is used globally.
  • Heap memory is divided into Young-Generation, Old-Generation etc.

Question 126

Question

MCQ▾

Which of the following concepts provides facility of using object of one class inside another class?

Choices

Choice (4)

a.

Composition

b.

Abstraction

c.

Inheritance

d.

Encapsulation

Answer

a.

Explanation

  • Composition allows using object of one class inside another class.
  • Composition is a special case of aggregation that is a restricted aggregation is called composition.
  • Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child)
  • When an object contains another object, if the contained object cannot exist without the existence of container object, then it is called composition. Example: House (parent) and Room (child) .
  • In both aggregation and composition, direction specifies, which object contains the other object.
Given the Image is Define the Composition

Developed by: