Docsity

Polymorphism in Java: Method Overloading and Overriding with Examples, Schemes and Mind Maps of Object Oriented Programming

Partial preview of the text

Download Polymorphism in Java: Method Overloading and Overriding with Examples and more Schemes and Mind Maps Object Oriented Programming in PDF only on Docsity!

Assignment

Course Code: CSE- Course Title: Object Oriented Programming

SUBMITTED TO

SUBMITTED BY

Date of Submission: 1 0.06.

Muntasir Karim Chowdhury

Lecturer

Department of Computer Science and Engineering

Feni University

Name: Hasan Imran Nazir

Student ID: 232031040

Batch: 31th (UG)

Department of CSE

Feni University

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.