<< Chapter < Page Chapter >> Page >

This output confirms that each overloaded version of the method is properly selected for execution based on the matching of method parameters to the formal argument list of each method.


Previous modules introduced overloading and overriding methods. This module concentrates on the use of method overloading to achieve compile-time polymorphism .

All classes in Java form a hierarchy with a class named Object at the root of the hierarchy. Thus, every class in Java is a direct or indirect subclass of the class named Object .

If a new class doesn't explicitly extend some other class, it will, by default, automatically extend the class named Object .

The Object class defines default versions of eleven different methods. These methods are inherited into all other classes, and some (those not declared final ) may be overridden to make their behavior more appropriate for objects instantiated from the new class.

Overloaded methods have the same name and different formal argument lists. They may or may not have the same return type.

Three of the eleven methods defined in the class named Object are overloaded versions of the method name wait . One version takes no parameters. A second version takes a single parameter of type long . The third version takes two parameters, one of type long , and one of type int .

The word polymorphism means something like one name, many forms . Polymorphism manifests itself in Java in the form of multiple methods having the same name.

Polymorphism manifests itself in three distinct forms in Java:

  • Method overloading
  • Method overriding through inheritance
  • Method overriding through the Java interface

This module concentrates on method overloading , sometimes referred to as compile-time polymorphism . This form of polymorphism is distinguished by the fact that the compiler selects a specific method from two or more overloaded methods on the basis of the types and the number of parameters passed to the method when it is called. The selection is made when the program is compiled (rather than being made later when the program is run) .

Overloaded methods may all be defined in the same class, or may be defined in different classes as long as those classes have a superclass-subclass relationship in the class hierarchy.

The sample program in this module illustrates three overloaded versions of the same method name with two of the versions being defined in a single class, and the other version being defined in the superclass of that class.

What's next?

The next module in this collection teaches you about assignment compatibility, type conversion, and casting for both primitive and reference types.

It also teaches you about the relationship between reference types, method calls, and the location in the class hierarchy where a method is defined.


This section contains a variety of miscellaneous information.

Housekeeping material
  • Module name: Java OOP: Polymorphism Based on Overloaded Methods
  • File: Java1608.htm
  • Published: 02/11/02

Financial : Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.

In the past, unknown individuals have misappropriated copies of my modules from cnx.org, converted them to Kindle books, andplaced them for sale on Amazon.com showing me as the author. I receive no compensation for those sales and don't know who doesreceive compensation. If you purchase such a book, please be aware that it is a bootleg copy of a module that is freelyavailable on cnx.org.

Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.

Complete program listings

A complete listing of the program is shown in Listing 4 below.

Listing 4 . Complete program listing.
/*File Poly01.java Copyright 2002, R.G.BaldwinProgram output is: m()m(int x) m(String y)**************************************/ class A extends Object{public void m(){ System.out.println("m()");}//end method m() }//end class A//===================================// class B extends A{public void m(int x){ System.out.println("m(int x)");}//end method m(int x) //---------------------------------//public void m(String y){System.out.println("m(String y)"); }//end method m(String y)}//end class B //===================================//public class Poly01{ public static void main(String[]args){ B var = new B();var.m(); var.m(3);var.m("String"); }//end main}//end class Poly01


Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
yes that's correct
I think
Nasa has use it in the 60's, copper as water purification in the moon travel.
nanocopper obvius
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
analytical skills graphene is prepared to kill any type viruses .
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?