Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is printed by the following code. Public class Inherit { public static void

ID: 3575337 • Letter: W

Question

What is printed by the following code. Public class Inherit { public static void main (String [ ] args) { Figure f = new Line ( ) ; tryme (f); } public static void tryme ( Figure f) { f. display ( ); } } public abstract class Figure { public void display ( ) { System. out. println (" Figure"); } } public clas Line extends Figure { public void display ( ) { System. out. println ("Line") ; } } public class shape extends Figure { public void display ( ) { System. out. printin ("Shape") ; } } Shape Line Figure none of the above

Explanation / Answer

public class Inherit
{
   public static void tryme(Figure f)
   {
       // call display function
       // here display function of parent class will be called first

       f.display();
   }
   public static void main(String[] args)
   {
       // create object of Line class
       Figure f = new Line();
       // call try me function
       tryme(f);  
   }
}

public class Line extends Figure
{
   public static void display()
   {
       System.out.println("Line");
   }
  
}


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


/*
output: C) Figure

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote