Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Polymorphism in Java

Overloaded methods are methods with the same name signature but either a different number of parameters or different types in the parameter list. For example 'spinning' a number may mean increase it, 'spinning' an image may mean rotate it by 90 degrees. By defining a method for handling each type of parameter you achieve the effect that you want.
Overridden methods are methods that are redefined within an inherited or subclass. They have the same signature and the subclass definition is used.
Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. This is the third basic principle of object oriented programming. Overloading and overriding are two types of polymorphism. Now we will look at the third type: dynamic method binding.
Assume that three subclasses (Cow, Dog and Snake) have been created based on the Animal abstract class, each having their own speak() method.

public class AnimalReference
{
  public static void main(String args[])
  Animal ref                 // set up var for an Animal
  Cow aCow = new Cow("Bossy"); // makes specific objects
  Dog aDog = new Dog("Rover");
  Snake aSnake = new Snake("Ernie");

  // now reference each as an Animal
  ref = aCow; ref.speak();
  ref = aDog; ref.speak();
  ref = aSnake; ref.speak();
}
Notice that although each method reference was to an Animal (but no animal objects exist), the program is able to resolve the correct method related to the subclass object at runtime. This is known as dynamic (or late) method binding.

 
     
   
Java Language Tutorial
 
  What is JAVA
What is JAVA
  Java an Object Oriented Language
Java an Object Oriented Language
  Java Keywords
Java Keywords
  Data Types
Data Types
  Java Operators
Java Operators
  Control Structure
Control Structure
  Arrays
Arrays
  Java Classes
Java Classes
  Java Constructors
Java Constructors
  Java Methods
Java Methods
  Java Method Overloading
Java Method Overloading
  Java Method Overriding
Java Method Overriding
  Java Nested Classes
Java Nested Classes
  Inheritance in Java
Inheritance in Java
  Interfaces in Java
Interfaces in Java
  Polymorphism in Java
Polymorphism in Java
  Exception Handling in Java
Exception Handling in Java
  Catching Exceptions
Catching Exceptions
  Embedding information in an exception object
Embedding information in an exception object
  The throws clause
The throws clause
  Checked and unchecked exceptions
Checked and unchecked exceptions
  The finally clause
The finally clause
  Applets in Java
Applets in Java
  Running an Applet
Running an Applet
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download  Internet Wealth Secrets Ebook Internet Wealth Secrets
   
Download Importance of Search Engine Article and Directory Submission Ebook Importance of Search Engine Article and Directory Submission
   
Download 10 Basics for Starting Your Online Business  Ebook 10 Basics for Starting Your Online Business
   
Download Linux Internals (to the power of -1)  Ebook Linux Internals (to the power of -1)
   
Download Design and Analysis of Algorithms: Course Notes  Ebook Design and Analysis of Algorithms: Course Notes
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz