Knowee
Questions
Features
Study Tools

1. Select four (4) statements taht can be onserted at line n1.CODE:public class Employee { public int salary;}public class Manager extends Employee { public int budget;}public class Director extends Manager { public int stockOptions;} public static void main(String[] args) { Employee employee = new Employee(); Manager manager = new Manager(); Director director = new Director(); //line n1 }}CHOICES:- employee.salary = 50000- director. salary = 80000- employee.budget = 20000- manager.budget = 100000- manager.stockOptions = 500;- director.stockOptions = 1000;

Question

  1. Select four (4) statements taht can be onserted at line n1.CODE:public class Employee { public int salary;}public class Manager extends Employee { public int budget;}public class Director extends Manager { public int stockOptions;} public static void main(String[] args) { Employee employee = new Employee(); Manager manager = new Manager(); Director director = new Director(); //line n1 }}CHOICES:- employee.salary = 50000- director. salary = 80000- employee.budget = 20000- manager.budget = 100000- manager.stockOptions = 500;- director.stockOptions = 1000;
...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The four statements that can be inserted at line n1 without causing a compile-time error are:

  • employee.salary = 50000
  • director.salary = 80000
  • manager.budget = 100000
  • director.stockOptions = 1000

The reason is that these statements are accessing properties that exist in their respective classes. For example, the Employee class has a salary property, so employee.salary = 50000 is valid. Similarly, the Manager class extends Employee and adds a budget property, so manager.budget = 100000 is valid. The Director class extends Manager and adds a stockOptions property, so both director.salary = 80000 and director.stockOptions = 1000 are valid.

The statements employee.budget = 20000 and manager.stockOptions = 500 would cause a compile-time error because the Employee class does not have a budget property and the Manager class does not have a stockOptions property.

This problem has been solved

Similar Questions

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();}

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;

public class Employee { public int id; public String name; private int sal; public Employee(int id, String name , int sal) { this.id = id; this.name = name; this.sal = sal; } public void setSal(int sal) { this.sal = sal; } public int getSal() { return sal; } public static List<Employee> getEmpList() { List<Employee> list = new ArrayList<>(); list.add(new Employee(111, "A", 2000)); list.add(new Employee(222, "B", 3000)); list.add(new Employee(333, "C", 4000)); list.add(new Employee(444, "D", 5000)); return list; }}public class Appp { public static void main(String[] args) { List<Employee> list = Employee.getEmpList(); for(Employee e : list) { //line 1 e.setSal(e.getSal()*2); //line 2 } //line 3 }}Choose the appropriate option to replace code line 1 to 3 to get the same output from the program. listEmployees.forEach(e -> e.setSal(e.getSal()*2));for(Employee e : listEmployees) {e -> e.setSal(e.getSal()*2);}for(Employee e : listEmployees) {forEach(e -> e.setSal(e.getSal()*2));}for(Employee e : listEmployees) {e.forEach() -> e.setSal(e.getSal()*2);}SubmitPowered by Infosys Wingspan

Select the correct answerA class Manager wants to implement an interface Salary. Which of the following is the correct way of implementing it?Optionsclass Manager implements Salary {}class Manager extends Salary {}class Manager imports Salary {}None of the mentioned

21. Write a Java program that creates a class hierarchy for employees of a company. The base class should be Employee, with subclasses Manager, Developer, and Programmer. Each subclass should have properties such as name, address, salary, and job title. Implement methods for calculating bonuses, generating performance reports, and managing projects

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.