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 aboveExplanation / 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
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.