Question: dynamic method dispatch

Ads

 
 
 

Share on Google+Share on Google+

seetaram
dynamic method dispatch
2 Answer(s)      7 years ago
Posted in : Java Beginners
can you give a good example for dynamic method dispatch (run time polymorphism)
Ads
View Answers

March 6, 2010 at 4:41 PM


Hi Friend,

In dynamic method dispatch,super class refers to subclass object and implements method overriding.
Example:

class Flower {
void which() {
System.out.println("A Beautiful flower.");
}
}
class Rose extends Flower {
void which() {
System.out.println("Rose");
}
}
class Lotus extends Flower {
void which() {
System.out.println("Lotus.");
}
}
class Test {

public static void main(String[] args) {
Flower ref1 = new Flower();
Flower ref2 = new Rose();
Flower ref3 = new Lotus();
ref1.which();
ref2.which();
ref3.which();
}
}

Thanks


September 2, 2012 at 4:02 PM


the process of binding appropriate version of derived class (which is derived from base class) with base class object is called dynamic method binding od dynamic method dispatch

example: class Flower { void which() { System.out.println("A Beautiful flower."); } } class Rose extends Flower { void which() { System.out.println("Rose"); } } class Lotus extends Flower { void which() { System.out.println("Lotus."); } } class Test {

public static void main(String[] args) { Flower ref1 = new Flower(); Flower ref2 = new Rose(); Flower ref3 = new Lotus(); ref1.which(); ref2.which(); ref3.which(); } }


Ads









Related Tutorials/Questions & Answers:
dynamic method dispatch - Java Beginners
dynamic method dispatch  can you give a good example for dynamic method dispatch (run time polymorphism)   Hi Friend, In dynamic method dispatch,super class refers to subclass object and implements method overriding
Dynamic method dispatch
Dynamic method dispatch Dynamic dispatch is a process of selecting, which methods to call at run-time. It is a mechanism by which a call to overridden method... dynamic dispatch in javaclass A { public void display
Advertisements
AsyncContext Interface dispatch method
In this section, you will learn about dispatch method of AsyncContext Interface
Dispatch Action - Struts
Dispatch Action  While I am working with Structs Dispatch Action . I am getting the following error. Request does not contain handler parameter named 'function'. This may be caused by whitespace in the label text
Struts dispatch action - Struts
Struts dispatch action  i am using dispatch action. i send the parameter="addUserAction" as querystring.ex: at this time it working fine. but now my problem is i want to send another value as querystring for example
Adduser.jsp in struts Dispatch
=insert" method="post"> <body> <table > <tr>
Struts Dispatch Action Example
Struts Dispatch Action Example       Struts Dispatch Action... function. Here in this example you will learn more about Struts Dispatch Action
DYNAMIC BINDING
DYNAMIC BINDING  WHAT IS DYNAMIC BINDING
dynamic report
dynamic report  i need complete code for generating dynamic report in jsp
Flex dispatch event example
mentioned in its constructor. This method is used to manually dispatch or run away an event. Method, to dispatch any event on the component can be applied... that will be run or dispatch away by the dispatchEvent method and the second
dynamic polymorphism
dynamic polymorphism  give an example for dynamic polymorphism?   Dynamic polymorphism is where a class overrides a superclass method...() method and provide its own implementation, and this is known at compile time
dynamic polymorphism
dynamic polymorphism  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism
Dynamic keyword
Dynamic keyword  hi....... What is the dynamic keyword used for in flex? give me the answer ASAP Thanks  Ans: Dynamic keyword-> Specifies that instances of a class may possess dynamic properties added
dynamic form
dynamic form  I need to make a dynamic form using php, for example, i will need a list of items which when we select one option another list...); } } </script> <form method="post" action="" name="form1"> <
JavaScript array push() method
JavaScript array push() method       In this example code of JavaScript array push() method we have described that how this JavaScript array's push() method can be used
dynamic textfields
dynamic textfields  Hi, I am a fresher and joined recently in one company. they gave me a desktop application project using swings.here is my detailed spec Screen 1 - The user enters the ingredients from a food product, saves
dynamic jquery statement
dynamic jquery statement  dynamic jquery statement
Dynamic form
Dynamic form  I need to make a dynamic form using jsp for example, i will need a list of items which when we select one option another list is modified ( like 2 lists of countries and citys ), and also a radio button wich once
dynamic calender
dynamic calender  hi i need the code to "insert date using GUI"   Hi Friend, Try the following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; class DatePicker{ int month
dynamic query
dynamic query  DECLARE QUERY VARCHAR2(32767); FIN_QUERY VARCHAR2(32767); CURSOR C IS (select distinct PORTFOLIO from MPE_TEST1); CURSOR C2 IS SELECT DISTINCT PORTFOLIO_LEVEL, PORTFOLIO FROM MPE_TEST1 ORDER
create dynamic array in javascript
create dynamic array in javascript  How to create dynamic array in javascript
php dynamic array checking
php dynamic array checking  php dynamic array checking
php dynamic array checking
php dynamic array checking  php dynamic array checking
PHP Dynamic CheckBox
PHP Dynamic CheckBox  Help with Dynamic Checkbox in PHP
Dynamic Types in Objective-C
Dynamic Types in Objective-C   ... with dynamic types. With these methods programmer can check that object is of the given class or not, given method is member of the given class or not etc. Table
STRUTS2 Dynamic data is not updated
STRUTS2 Dynamic data is not updated  Hi All, I am new in struts and try to make an application in struts2. Need help on dynamic data content... method for using that variable which i was fetched through database now
STRUTS2 Dynamic data is not updated
STRUTS2 Dynamic data is not updated  Hi All, I am new in struts and try to make an application in struts2. Need help on dynamic data content... method for using that variable which i was fetched through database now
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
Dynamic include jsp
Dynamic include jsp  I need dynamic include jsp page with an example
static page and dynamic pages?
static page and dynamic pages?  what is the static page and dynamic pages
static page and dynamic pages?
static page and dynamic pages?  what is the diff between static page and dynamic pages
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads