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.
The ratio between the cost price of product G and H is 8:7 respectively. Each of the products was marked 25% above its cost price. If the MRP of product...
A shopkeeper buys an item for Rs 400 and sells it for Rs 460. What is his profit percentage?
The cost price of 23 mangoes is Rs.200. Because of bad quality of mangoes, the shopkeeper has to sell mangoes at a loss that is equal to selling price o...
If A : B = 8:3 and A is 25 more than B then find the sum of A and B.
A seller purchased certain number of watches at prices ranging from Rs. 850 to Rs. 1150 and sold them at price ranging from Rs. 1000 to Rs. 1300. Find t...
- A dairy owner buys 20 liters of milk at Rs. 50 per liter. While selling, he uses a faulty measure that shows 1020 milliliters instead of 1000 milliliters b...
The cost of 5 guns is equal to the cost of 12 magazines. If a seller marks the price of each gun 50% higher than its cost price and gives away one magaz...
A man bought 5 articles K, L, M, N, O at Rs. 620 each. Selling prices of K,L, M,N and O were x, x+ 20, x +25, x +75, x +80 respectively. Overall profit ...
If the selling price of an article is Rs. 540 and the cost price is Rs. 450, what is the profit percentage?
- A dishonest shopkeeper marks up the price of his produce by 40% on the cost price and sells it providing a discount of 25%. If he uses 800 gram as weight i...