Results 1 to 2 of 2
  1. #1
    dejulial is offline Member
    Join Date
    Mar 2012
    Rep Power

    Default Compile-time Polymorphism or Run-time Polymorphism ?

    Hi everyone,

    please check out the following code first: (I defined an anonymous inner class here)
    __________________________________________________ ______________________

    class Popcorn {
    public void pop() {
    class Food {
    Popcorn p = new Popcorn() {
    public void pop() {
    System.out.println("anonymous popcorn");

    __________________________________________________ _______________________

    In this case, is it a compile-time polymorphism or a run-time polymorphism when the anonymous inner class is involved ?
    Does the compiler know which pop() method to call at the compile-time?
    Is there any way I can see if it is happening at compile-time or run-time?

    Thanks a lot!!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Compile-time Polymorphism or Run-time Polymorphism ?

    What happens when you compile and execute the program?

    The javap command will disassemble the class file so you can see what the compiler generated.

Similar Threads

  1. the compile time error is below
    By nicholil in forum New To Java
    Replies: 2
    Last Post: 11-07-2010, 01:52 AM
  2. Runtime/Compile Time Exceptions
    By in forum New To Java
    Replies: 1
    Last Post: 10-18-2010, 11:32 AM
  3. High Compile Time
    By Mojito_gr in forum Advanced Java
    Replies: 7
    Last Post: 08-02-2010, 04:47 AM
  4. Doubt in run time polymorphism
    By Thennarasu in forum New To Java
    Replies: 4
    Last Post: 07-21-2009, 08:17 AM
  5. Help with Compile time errors
    By bri1547 in forum New To Java
    Replies: 2
    Last Post: 08-24-2008, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts