


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This assignment provides a clear and concise explanation of polymorphism in java, focusing on two key mechanisms: compile-time polymorphism (method overloading) and runtime polymorphism (method overriding). It illustrates these concepts with practical examples, demonstrating how to overload methods within a class and override methods inherited from a parent class. The assignment also includes a section on comparing strings in java, highlighting the differences between using the equals() method and the == operator.
Typology: Schemes and Mind Maps
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Course Code: CSE- Course Title: Object Oriented Programming
Date of Submission: 1 0.06.
Polymorphism in Java
In Java, polymorphism manifests through two primary mechanisms:
Compile-Time Polymorphism (Method Overloading)
This technique leverages the concept of method overloading within a class.
Example:
In this example, the calculateArea method is overloaded. The compiler selects the appropriate method (calculateArea with no arguments, calculateArea with a single double argument, or calculateArea with two double arguments) based on the arguments used in the call.
Compare two strings in Java
Using the equals() method
This is the recommended approach for comparing strings based on their content.
Using the == operator
This operator compares the object references themselves, not the string content.