Ask Question

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");

+4
Answers (1)
  1. 3 May, 08:37
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers