Ask Question
14 May, 03:10

Public class Robot

{

public Robot () { System. out. println ("Tom Servo"); }

public Robot (String name) { System. out. println (name); }

}

public class Cyborg extends Robot

{

public Cyborg () { System. out. println ("Robocop");

public Cyborg (String name) { System. out. println (name);

}

public class Cyberman extends Cyborg

{

public Cyberman () { super (); System. out. println ("Cyberman"); }

public Cyberman (String name) { super (name); System. out. println (name);

}

Given the class hierarchy above, what output would be generated with the following statement: Cyberman one = new Cyberman ("Bob");

+2
Answers (1)
  1. 14 May, 04:44
    0
    Tom Servo

    Bob (prints inside Cyborg constructor)

    Bob (prints inside Cyberman constructor)

    Explanation:

    The above type of inheritance is multilevel inheritance where Robot is super class and Cyborg and Cyberman are sub classes.

    So in above statement

    Cyberman one = new Cyberman ("Bob"); it calls the Cyberman (String name) in which super (name) calls Cyborg (String name) but before executing the body inside Cyborg constructor it first calls super class default constructor (i. e., Robot ()) so the output of the above statement is

    Tom Servo

    Bob (prints inside Cyborg constructor)

    Bob (prints inside Cyberman constructor)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Public class Robot { public Robot () { System. out. println ("Tom Servo"); } public Robot (String name) { System. out. println (name); } } ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers