Since, Inheritance guarantees minimum base class behaviour, a method depending upon super class or super interface can still accept an object of the base class and can authenticate it. For example, by using Inheritance you can define new user types in an Authentication System and by using Polymorphism you can take advantage of already written authentication code. Both Polymorphism and Inheritance allow Object oriented programs to evolve.you can pass an instance of this class to a method which accepts Serializable, or to Collections.sort() which accepts a Comparator. For example, a class can be Runnable, Comparator and Serializable at the same time because all three are interfaces. It also allows data and code to be linked together. OOPs incorporates real-world concepts such as inheritance, polymorphism, and concealing into programming. As such, it is important for developers to have a solid understanding of Java OOPS concepts. 3472 Reader (s) Java is an object-oriented programming language that is widely used in developing web and mobile applications. Java doesn't allow multiple inheritance of classes, but allows multiple inheritance of Interface, which is actually required to implement Polymorphism. Answer: Object-Oriented Programming (OOPs) is a programming style that emphasizes objects above functions and procedures. Java OOPS Interview Questions and Answers.Without Polymorphism it's not possible for a child to execute its own behaviour while represented by a Parent reference variable, but with Polymorphism it can be done. On the other hand Polymorphism allows child to redefine already defined behaviour inside the parent class. Inheritance encourages code reusability by allowing child class to inherit behavior from the parent class. Inheritance defines parent-child relationship between two classes, polymorphism takes advantage of that relationship to add dynamic behavior in your code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |