120 likes | 141 Views
Java is a most popular, robust, secure, platform independent and multithreading based high level programming language, because of this it is preferably used by many programmers.
E N D
Index Four types of polymorphism in Java What is Java polymorphism
ExlTech has come up with the Exclusive Java Training course.Hurry and grab the opportunity to become successful Java professional in worlds up growing technologies. Types of polymorphism in Java There are four types of polymorphism in Java: 1. Coercion is an operation serves multiple types through implicit type conversion. For example, you divide an integer by another integer or a floating-point value by another floating-point value. If an operand is an integer and the other operand is a floating-point value, the compiler (implicitly) forces the integer into a floating-point value to prevent a type error. (There is no division operation that supports an integer operand and a floating-point operand.) Another example is passing a subclass object reference to the superclass parameter of a method. The compiler forces the subclass type to the superclass type to limit operations to those of the superclass.
2. What do you mean? Overload refers to the use of the same operator symbol or method name in different contexts. For example, you can use + to perform integer addition, floating-point addition, or string concatenation, depending on the types of its operands. In addition, multiple methods with the same name can appear in a class (by Declaration and/or inheritance).
3. Parametric polymorphism defines that in a class Declaration, a field name with different types and a method name with different parameter and return types can be linked. The field and method can then take different types in each class instance (object). For example, a field of type Double (A member of the Java standard class library that encloses a double value) and a method can return a Double in an object. Java supports parametric polymorphism via generics, which I will discuss in a future article. https://www.exltech.in/java-training.html
4. Subtype means that a type can serve as a subtype of another type. When a subtype instance appears in a Supertype context, running a supertype operation on the subtype instance will cause the subtype to run. For example, consider a code fragment that draws arbitrary shapes. You can Express these characters code more concise by introducing a Shape class with a draw () method; by introducing Circle, Rectangle, and other sub-classes, the draw () override.; and by calling the draw () method for each instance. When you call draw (), the draw () method of the Circle, Rectangle, or other Shape instance is called. We say that there are many forms of the draw () method of Shape.
This tutorial introduces the subtype polymorphism. Learn more about upcasting and late binding, abstract classes (cannot be instantiated) abstract methods (which can not be called). You will also learn downcasting and runtime type identification and get a first look at co-variant return types. I save parametric polymorphism for a future tutorial.
Visit Us: https://www.exltech.in/