Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We have a class Person that has the instance variables name and age. It has a co

ID: 3569792 • Letter: W

Question

We have a class Person that has the instance variables name and age. It has a constructor that takes both of those values in as parameters and also a default constructor. Fill in the rest of the class SuperHero with the proper constructors: A default constructor that sets the superPower to a default value and also calls the Person's default constructor, and another constructor that takes in the super hero's power along with the name and age. Make sure they call the parent's constructor. It should also have an accessor and mutator for its instance variable superPower. Furthermore Person has a method public void printInfo(). Override this hero's calling the parent's printInfo along with printing the super hero's power. public class SuperHero { String superPower;

Explanation / Answer

SuperHero.java


public class SuperHero extends Person{

String superPower;
  
public SuperHero() {
super();
  
superPower="";
}
  
public SuperHero(String sp, String n, int a){
super(n, a);
  
superPower=sp;
}
  
public String getSuperPower()
{
return superPower;
}
  
public void setSuperPower(String sp)
{
superPower=sp;
}
  
@Override
public void printInfo()
{
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Superpower: "+superPower);
}
  
}

------------------------------------------------------------------------------------------------------------------------

Person.java


public class Person {

public String name;
public int age;

public Person() {

}

public Person(String n, int a) {
name = n;
age = a;
}

public void printInfo() {
System.out.println("Name: "+name);
System.out.println("Age: "+age);
}

}

-------------------------------------------------------------------------------------------

Test.java // for testing the above classes


public class Test {

  
  
public static void main(String[] args) {
// TODO code application logic here
  
SuperHero sp1 = new SuperHero("fly", "clark", 25);
sp1.printInfo();
  
}
  
}

---------------------------------------------------------------------------------------------------

OUTPUT

Name: clark
Age: 25
Superpower: fly

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote