Biology Forums - Study Force

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



Title: What is printed? public class Inherit{class Figure{void display( ){System.out.println("Figure");}} c
Post by: Izaganag on Sep 21, 2015
What is printed?

   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
Rectangle
Box
B) Rectangle
Box
C) Figure
Figure
Figure
D) Syntax error; this code won't compile or execute
E) none of the above


Title: Re: What is printed? public class Inherit{class Figure{void display( ){System.out.println("Figure");
Post by: eurocoin on Sep 21, 2015
A?


Title: Re: What is printed? public class Inherit{class Figure{void display( ){System.out.println("Figure");}} c
Post by: Izaganag on Sep 28, 2015
I regret taking this computer science course. Should just stick to history :P Thanks for your help.