22.11.2023
0
Beğenme
107
Görüntülenme
Read full article about polymorphism and runtime polymorphism in java
Polymorphism is one of the four essential principles of object-oriented programming (OOP) that Java supports. It enables the treatment of objects of distinct classes as objects of a common interface or superclass. Polymorphism in Java is classified into two types: compile-time polymorphism (also known as method overloading) and runtime polymorphism (also known as method overriding).
Compile-time Polymorphism (Method Overloading):
Method overloading is a feature that allows a class to have many methods with the same name as long as their parameter lists differ (in terms of the amount or type of parameters).
Runtime Polymorphism (Method Overriding):
Method overloading is a feature that allows a class to have many methods with the same name as long as their parameter lists differ (in terms of the amount or type of parameters).
polymorphism in java,what is polymorphism in javaIn this example, even though the reference variable animal is of type Animal, it refers to an instance of Dog. During runtime, the sound() method of the Dog class is invoked.
Polymorphism is an important notion in object-oriented programming because it provides for code flexibility and expansion. By programming to interfaces or basic classes rather than specific implementations, you can develop more generic and reusable code.
Kullanıcı yorumlarını görüntüleyebilmek için kayıt olmalısınız!