Top Posters
Since Sunday
g
3
3
2
J
2
p
2
m
2
h
2
s
2
r
2
d
2
l
2
a
2
New Topic  
Izaganag Izaganag
wrote...
Posts: 686
Rep: 2 0
8 years ago
What is printed by this code?

   public class Inherit
   {

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

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

      class Box extends Figure
      {
         void display( )
         {
            System.out.println("Box");
         }
         void display(String s)
         {
            System.out.println("This is printed: " + s);
         }
      }

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

      public static void main(String[ ] args)
      {
         new Inherit( );
      }
   }
A) Figure
Figure
Figure
Figure
B) Figure
Rectangle
C) Rectangle
Figure
Box
Figure
D) Figure
Rectangle
Figure
Box
E) Syntax errorthis code won't even compile
Textbook 
Java Software Solutions: Foundations of Program Design

Java Software Solutions: Foundations of Program Design


Edition: 7th
Authors:
Read 310 times
3 Replies
Replies
Answer verified by a subject expert
habibtihabibti
wrote...
Top Poster
Posts: 1486
8 years ago
Sign in or Sign up in seconds to unlock everything for free
More solutions for this book are available here
1

Related Topics

Izaganag Author
wrote...
8 years ago
That makes life a whole lot easier, thank you for answering.
wrote...
8 years ago
Guys, you see that "vote as best answer" button below the answer, CLICK IT Slight Smile Slight Smile
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1073 People Browsing
 114 Signed Up Today
Related Images
  
 238
  
 371
  
 588
Your Opinion
Which industry do you think artificial intelligence (AI) will impact the most?
Votes: 352