![]() What is Compile time polymorphism (Static polymorphism)?Īns: A polymorphism where object binding with methods happens at compile time is called static polymorphism or compile-time polymorphism. Without polymorphism, it is not possible for a child class to execute its own behavior.ħ. On the other hand, polymorphism enables child class to redefine already defined behavior inside parent class. Inheritance helps in code reusability in child class by inheriting behavior from parent class. On the other hand, polymorphism takes the advantage of that relationship to make the program more dynamic.ī. Inheritance represents the parent-child relationship between two classes. What are the differences between Polymorphism and Inheritance in Java?Īns: The differences between polymorphism and inheritance in java are as follows:Ī. The main benefit of using polymorphism is when we can provide implementation to an abstract base class or an interface.Ħ. Using polymorphism, we can achieve flexibility in our code because we can perform various operations by using methods with the same names according to requirements.ī. What are the advantages of Polymorphism?Īns: There are the following advantages of polymorphism in java:Ī. ![]() How is Inheritance useful to achieve Polymorphism in Java?Īns: Inheritance represents the parent-child relationship between two classes and polymorphism take the advantage of that relationship to add dynamic behavior in the code (or to make the program more dynamic).ĥ. The subclasses can have their own unique implementation for certain features and can also share some of the functionality through inheritance.Ĥ. ![]() Ans: Polymorphism in Java can be primarily achieved by subclassing or by implementing an interface.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |