Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

What is dynamic polymorphism in java? What is the significance of it ?

807603Dec 24 2007 — edited Dec 24 2007
What is dynamic polymorphism in java? What is the significance of it ?

Comments

807603
http://www.google.com/search?q=dynamic+polymorphism+java

~
807603
yawmark wrote:
http://www.google.com/search?q=dynamic+polymorphism+java

~
Isn't this the time of year when we do the googling for posters too lazy to do their own homework? I guess not ;-)
807603
Isn't this the time of year when we do the googling for posters too lazy to do their own homework?
http://groovy.codehaus.org/

;o)

Merry Christmas, Dr. L.

~
807603
New Year's resolution: Be groovy in the new year!

groovy.util.GString --- tee-hee
807603
"Dynamic polymorphism" is a phrase that was made up by someone who had no clue what they were talking about. If you want useful information, just look up "polymorphism".
807603
I much prefer static polymorphism myself.
807603
there are two polymorphism, which are static and dynamic.
as you know, static polymorphism is done by compiler, but dynamic polymorphism is done by run-time.
Thus, the below can explain it. the compiler cannot decide what the "Object o" will be, so it will be done during run time.

public class B implements C{

	public void doSomething() {
		System.out.println("i am B");
		
	}
	
}

public interface C {
	public void doSomething();

}

public class A implements C{
	
	static ArrayList<C> al = new ArrayList();
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Random r = new Random();
		if(r.nextInt()%2 == 0){
			al.add(new B());
		}else{
			al.add(new A());			
		}
		
		
		C o = al.get(al.size()-1);
		o.doSomething();
		

	}
	public void doSomething() {
		System.out.println("hello A");
		
	}


}
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 21 2008
Added on Dec 24 2007
7 comments
269 views