Knowee
Questions
Features
Study Tools

Given:1. public class Employee {2. String name;3. double baseSalary;4. Employee(String name, double baseSalary) {5. this.name = name;6. this.baseSalary = baseSalary;7. }8. }And:11. public class Salesperson extends Employee {12. double commission;13. public Salesperson(String name, double baseSalary,14. double commission) {15. // insert code here16. }17. } Which code, inserted at line 17, completes the Salesperson constructor?Select one:a.this.commission = commission;b.this.commission = commission;super();c.this.commission = commission;super(name, baseSalary);d.super();commission = commission;e.super();this.commission =commission;f.super(name, baseSalary);this.commission = commission;

Question

Given:1. public class Employee {2. String name;3. double baseSalary;4. Employee(String name, double baseSalary) {5. this.name = name;6. this.baseSalary = baseSalary;7. }8. }And:11. public class Salesperson extends Employee {12. double commission;13. public Salesperson(String name, double baseSalary,14. double commission) {15. // insert code here16. }17. } Which code, inserted at line 17, completes the Salesperson constructor?Select one:a.this.commission = commission;b.this.commission = commission;super();c.this.commission = commission;super(name, baseSalary);d.super();commission = commission;e.super();this.commission =commission;f.super(name, baseSalary);this.commission = commission;

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is:

f. super(name, baseSalary); this.commission = commission;

Explanation:

In Java, the keyword 'super' is used to call the parent class constructor. In this case, the parent class is Employee and its constructor takes two parameters: name and baseSalary. So, we need to call this constructor from the child class (Salesperson) constructor and pass the required parameters. This is done using 'super(name, baseSalary);'.

After calling the parent class constructor, we can initialize the Salesperson specific variable 'commission'. This is done using 'this.commission = commission;'. 'this' keyword in Java is used to refer to the current object, which would be an instance of Salesperson in this case.

So, the complete code to be inserted at line 15 would be:

super(name, baseSalary); this.commission = commission;

This problem has been solved

Similar Questions

10.  abstract public class Employee {11.  protected abstract double getSalesAmount();12.  public double getCommision() {13.  return getSalesAmount() * 0.15;14.  }15.  }16.  class Sales extends Employee {17. 18.  }Which method, inserted at line 17, correctly complete the Sales class?

public class Employee {private int id;private String name;private float salary;private String pancardno;public Employee(){System.out.println("In default constructor");}public Employee(int id, String name, float salary) {this.id = id;this.name = name;this.salary = salary;}public Employee(int id, String name, float salary, String pancardno) {this(id,name,salary); this.pancardno = pancardno; }this();}

You have a class Student:public class Student{ public int studentId; public String studentName; public String studentGrade; public Student() { } public Student(int studentId, String studentName, String studentGrade){ this.studentId = studentId; this.studentName = studentName; this.studentGrade = studentGrade; }}You have a child class CollegeStudent:public class CollegeStudent extends Student {}Then you execute the following snippet of code:CollegeStudent myCollegeStudent = new CollegeStudent(1, "Alice", "3rd");What is the error in this snippet of code?Instruction: Choose the option that best answers the question. Answer ChoicesYou cannot specify multiple constructors for the parent class, though this is allowed in child classesYou cannot use the parameterized constructor in the base class to instantiate the CollegeStudent derived classYou need to have additional constructors in the base class to support the instantiation of the CollegeStudent derived classYou have to use the “object” keyword to create an object of a derived class

You have a class Student:public class Student { public int studentId; public String studentName; public String studentGrade; public Student() { studentId = 1; studentName = null; studentGrade = "1st"; }}You have a child class CollegeStudent:public class CollegeStudent extends Student {}Then you execute the following snippet of code:CollegeStudent myCollegeStudent = new CollegeStudent();System.out.println(myCollegeStudent.studentName);What will be returned by this code?Instruction: Choose the option that best answers the question. Answer ChoicesAn exception will be thrown indicating there is no studentName variable in the CollegeStudent derived classAn exception will be thrown indicating that the studentName variable is not accessible in the derived class CollegeStudentfalsenull

Match the constructor Types based on Objects created.When constructor is provided by the developer for the class EmployeeEmployee e = new Employee();Answer 1When constructor not written in the class EmployeeEmployee e = new Employee(101,"Peter" );Answer 2When constructor not written in the class EmployeeEmployee e = new Employee();Answer 3When constructor is provided by the developer for the class EmployeeEmployee e = new Employee(101,"Peter" );

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.