Answer to Question #255971 in Java | JSP | JSF for Shayla

Question #255971

Finish the Teacher constructor. Use super to use the Person constructor to set the fields 

inherited from Person. It should print “Destini 20” followed by “Erica 55 Masters in Teaching”.

public class Person

{

 private String name;

 private int age;

 public Person(String name, int age)

 {

 this.name = name;

 this.age = age;

 }

 public String getName() { return this.name; }

 public int getAge() { return this.age; }

 public String toString()

 {

 return getName() + " " + getAge();

 }

 public static void main(String[] args)

 {

 Person p = new Person("Destini", 20);

 System.out.println(p);

 Teacher p2 = new Teacher("Erica", 55, "Masters in Teaching");

 System.out.println(p2);

 }

}

class Teacher extends Person

{

 String degree;

 public String getDegree() { return this.degree; }

 public String toString()


{

 return getName() + " " + getAge() + " " + getDegree();

 }

 public Teacher(String name, int age, String theDegree)

 {

 // ADD CODE HERE

 }

}


1
Expert's answer
2021-10-24T18:48:46-0400
public class Person
{
    private String name;
    private int age;


    public Person(String name, int age)
    {
        this.name = name;
        this.age = age;
    }


    public String getName() { return this.name; }


    public int getAge() { return this.age; }


    public String toString()
    {
        return getName() + " " + getAge();
    }


    public static void main(String[] args)
    {
       Person p = new Person("Destini", 20);
       System.out.println(p);
       Teacher p2 = new Teacher("Erica", 55, "Masters in Teaching");
       System.out.println(p2);
    }
}


class Teacher extends Person
{
    String degree;


    public String getDegree() { return this.degree; }


    public String toString()
    {
        return getName() + " " + getAge() + " " + getDegree();
    }


    public Teacher(String name, int age, String theDegree)
    {
       super("Destini", 20);
       theDegree = "Master";
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS