Menu

Two Main Object Oriented Features Java Programming Language Ability Inherit Code One Class Q43835549

Two of the main object-oriented features of the Java programminglanguage are the ability to inherit the code of one class, and theability to override some of the inherited methods to affect apolymorphic behavior. In this discussion, you will explore both ofthese concepts and how should they be programmed.

Examine the loaded project, and answer these questions:

  • What would be the output of this program when it is run?
  • Why does calling toString() on the Person and Student objectsreturn their names (“Person” and “Student”) while callingtoString() on the Employee object returns “Person”?
  • How can we fix this such that calling toString() on theEmployee object return its name as well?

Provide a screenshot of your result of your fix.

PLEASE Explain, briefly, how you completed thisexercise, the algorithm you used (via pseudo code or otherdescription tools), the major issues you faced. and how you solvedthese issues.

CODE BELOW:

package u1d1_extendoverride;

public class U1D1_ExtendOverride {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
  
System.out.printf(
“toString() on Person returns => t%sn”,
new Person().toString());
   System.out.printf(
“toString() on Student returns => t%sn”,
new Student().toString());
   System.out.printf(
“toString() on Employee returns => t%sn”,
new Employee().toString());
}
}

class Person {
protected String name;
protected String address;
protected String phoneNumber;
protected String email;

public String toString() {
return “Person”;
}
}

class Student extends Person {
public static int FRESHMAN = 1;
public static int SOPHOMORE = 2;
public static int JUNIOR = 3;
public static int SENIOR = 4;

protected int status;

public String toString() {
return “Student”;
}
}

class Employee extends Person {
protected String office;
protected int salary;
}

Expert Answer


Answer to Two of the main object-oriented features of the Java programming language are the ability to inherit the code of one cla…

OR