Assume we have a class Person that has the instance variables name and age. It a
ID: 3770140 • Letter: A
Question
Assume we have a class Person that has the instance variables name and age. It also has a default constructor, and has a constructor that takes both of those values in as parameters. Fill in the rest of the class SuperVillain which inherits Person with the proper contstructors:
a. A default constructor that sets the super power to a default value, initalizes the array of henchmen ( any size is fine), and also calls the Person's default constructor
b. A parameterized constructor that takes in the super villain's power, an array of Person for thier henchmen, a name, and age. Make sure they call the parent's constructor.
Also Person has a method printInfo. Override this method calling the parent's printInfo along with printing the villain's power, and print out the information of every henchman. You only have to write the constructors and the method denoted, and you do not have to worry about error checking.
Explanation / Answer
I don't understand the requirement of henchmen. you can declare one more array of Person in this code.
class Person{
private String name;
private int age;
public Person(){
}
public Person(String name,int age){
this.name = name;
this.age = age;
}
public void printInfo(){
System.out.println(name + " is " + age + " years old.");
}
}
public class SuperVillain extends Person{
String superPowers;
public SuperVillain(){
superPowers = "";
super();
}
public SuperVillain(String name,int age,String powers){
superPowers = powers;
super(name,age);
}
public void printInfo(){
System.out.println(name + " is " + age + " years old and has "+ superPowers + " powers.");
}
}