Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners dynamic method dispatch
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


seetaram
dynamic method dispatch
2 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners


can you give a good example for dynamic method dispatch (run time polymorphism)

Advertisement
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(); } }



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
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 report
dynamic report  i need complete code for generating dynamic report in jsp
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
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 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"> <
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
method
method   how and where, we can define methods ? can u explain me with full programme and using comments
method
method  can you tell me how to write an abstract method called ucapan() for B2 class class A2{ void hello(){ system.out.println("hello from A2"); }} class B2 extends A2{ void hello(){ system.out.println("hello from B2
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
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
 

 

 

DMCA.com