QuestionQ2

Working with Inheritance

Given these classes:

Question Image

and this main method:

Question Image

Which two options compile when placed at line n1 in the main method?

Choose two
  • A director.stockOptions = 1_000;
  • B employee.salary = 50_000;
  • C manager.budget = 1_000_000;
  • D manager.stockOption = 500;
  • E employee.budget = 200_000;
  • F director.salary = 80_000;
Explanation

Each variable has the declared type Employee, so compile-time member access permits its public salary field only. Although director refers to a Director object at runtime, fields such as budget and stockOptions are not accessible through an Employee-typed reference without a cast.

Community Discussion

No comments yet. Be the first to start the discussion!