Question
Which of the following best represents the concept of
polymorphism in Object-Oriented Programming?ÂSolution
Polymorphism in Object-Oriented Programming (OOP) allows methods to be defined in different forms across different derived classes, typically by overriding or overloading methods. This enables a single method to exhibit multiple behaviors, depending on the object that invokes it. For example, a base class method draw() in a shape class could be defined differently in derived classes like Circle and Rectangle, where each class implements its unique version of draw(). This approach promotes flexibility, reduces code duplication, and allows developers to manage code easily as new classes are added, embodying one of OOP’s core principles. Polymorphism is critical for creating extensible and maintainable code, as it enables a system to process objects of various types through a common interface. Option A (Encapsulation) - Encapsulation is the OOP principle of hiding internal details and exposing only necessary features through a class interface, which differs from polymorphism’s focus on varied behaviors. Option C (Aggregation) - Aggregation describes a "has-a" relationship between classes, where one class contains references to another, unrelated to polymorphic behavior. Option D (Encapsulation) - This concept of grouping related fields and methods within a class refers to encapsulation, not polymorphism. Option E (Unrelated Classes) - Allowing objects of unrelated classes to connect without a common functionality does not represent polymorphism, which requires shared interfaces or inheritance.
Average age of a class of 28 students is 10 years. Average age of the class is increased by 12 months if the age of the teacher is included. Find...
The ratio of the present ages of P and Q is 7:4 respectively. If the age of P 13 years hence from now will be 125% more than the age of Q 4 years ago fr...
The average age of three children is 14 years. If their ages are in the ratio 1:2:3. Find the age of the youngest child.
A candidate just passed by getting 60 answers correct by attempting 132 of the total questions. Find the total number of questions in the examination if...
The total number of students in class A and B is 72. The number of students in A is 40% more than that in B. The average marks of students in B are 50% ...
If a:b:c = 3:4:6, and (5a + 3c) = 132, then find the value of '3b'.
The average of 27 numbers is 20.The average of first 13 numbers is 15 and that of the last 13 numbers is 18. What will be the 27th number?
- The average salary of X, Y, and Z is Rs. 22000 and the average salary of P and Q is Rs. 15000. If the savings of X is 60% of the average salary of all five...
The average weight of 14 persons increases by 3.5 kg when a new person comes in place of one of them weighing 48 kg. The weight of the new person is.
- Three numbers are given such that when the average of any two numbers is added to the third number, the resulting sums are 250, 240, and 230. Determine the...