Question: What will be displayed when the following code executes? class One { void display ( ) { System.out.println ( One ) ; }

What will be displayed when the following code executes?
class One
{
void display ()
{ System.out.println ("One"); }
}
class Two extends One
{
void display ()
{ System.out.println ("Two"); }
}
public class Main
{ public static void main (String[]args)
{
One obj1= new One ();
Two obj2= new Two ();
One obj3= new Two ();
One obj4= obj2;
obj1.display ();
obj2.display ();
obj3.display ();
obj4.display ();
}
}
One Two One Two
One Two One One
One Two Two Two
One Two Two OneWhat will be displayed when the following code executes?
class One
{
void display ()
{ System.out.println ("One"); }
}
class Two extends One
{
void display ()
{ System.out.println ("Two"); }
}
public class Main
{ public static void main (String[]args)
{
One obj1= new One ();
Two obj2= new Two ();
One obj3= new Two ();
One obj4= obj2;
obj1.display ();
obj2.display ();
obj3.display ();
obj4.display ();
}
}
One Two One Two
One Two One One
One Two Two Two
One Two Two One

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!