Biology Forums - Study Force

Science-Related Homework Help Computer Studies Topic started by: Izaganag on Sep 21, 2015



Title: What is printed by the following code? Consider the polymorphic invocation.public class Inherit{ cl
Post by: Izaganag on Sep 21, 2015
What is printed by the following code?  Consider the polymorphic invocation.
   public class Inherit
   {

      class Figure
      {
         void display( )
         {
            System.out.println("Figure");
         }
      }

      class Rectangle extends Figure
      {
         void display( )
         {
            System.out.println("Rectangle");
         }
      }

      class Box extends Figure
      {
         void display( )
         {
            System.out.println("Box");
         }
      }

      Inherit( )
      {
         Figure f = new Figure( );
         Rectangle r = new Rectangle( );
         Box b = new Box( );
         f.display( );
         f = r;
         f.display( );
         f = b;
         f.display( );
      }

      public static void main(String[ ] args)
      {
         new Inherit( );
      }
}
A) Figure
Figure
Figure
B) Figure
Rectangle
Box
C) Rectangle
Box
D) Syntax error.  This code won't compile or execute
E) none of the above


Title: Re: What is printed by the following code? Consider the polymorphic invocation.public class Inherit
Post by: habibti on Sep 25, 2015
Content hidden


Title: Re: What is printed by the following code? Consider the polymorphic invocation.public class Inherit{ cl
Post by: Izaganag on Sep 28, 2015
That makes life a whole lot easier, thank you for answering.


Title: Re: What is printed by the following code? Consider the polymorphic invocation.public class Inherit{ cl
Post by: habibti on Sep 28, 2015
Guys, you see that "vote as best answer" button below the answer, CLICK IT :) :)