× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
w
3
w
3
e
3
3
r
3
g
2
2
b
2
M
2
V
2
f
2
c
2
New Topic  
DePeet DePeet
wrote...
Posts: 338
Rep: 0 0
6 years ago
What is the output of the following 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
Rectange
b.   Figure
Rectangle
Figure
Box
c.   Figure
Figure
Figure
Figure
d.   Syntax error; this code won't compile
e.   None of these
Read 74 times
1 Reply
Replies
Answer verified by a subject expert
se7ense7en
wrote...
Posts: 327
Rep: 0 0
6 years ago
Sign in or Sign up in seconds to unlock everything for free
1

Related Topics

DePeet Author
wrote...

6 years ago
Brilliant
wrote...

Yesterday
Thanks for your help!!
wrote...

2 hours ago
Thanks
New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  407 People Browsing
Related Images
  
 242
  
 283
  
 290
Your Opinion
What's your favorite funny biology word?
Votes: 401