Answer to Question #258546 in Java | JSP | JSF for liza

Question #258546

 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) 

 { 


1
Expert's answer
2021-10-29T11:55:16-0400


package person;




public class Person 


{ 


 private String name; 


 private int age; 


Person(){
    
}


 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(name, age);
     
     degree = theDegree;
 }
 }

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