Concept explainers
Suppose the class SportsCar is a derived class of a class Automobile, and suppose also that the class Automobile has public method accelerate and addGas. Will an object of the class SportsCar have methods named accelerate and addGas? If so, do these method perform the exact same actions in the class SportsCar as in the class Automobile?
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
C++ How to Program (10th Edition)
Artificial Intelligence: A Modern Approach
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Define a class named Employee. This class should extend the Person class from the previous question. The class should have a constructor, which takes the name, age, employer (String) and salary (int) as parameters (in that order). The first two parameters should be passed to the constructor of the superclass and the value of the last two parameters should be stored in instance variables. The class should define the methods, getSalary which returns the salary of the employee and getEmployer which returns the name of the employer. Any methods from the previous question that need to be overridden should be overridden! Use super and instanceof as appropriate. I.e., for the following methods you should be able to call the method in the superclass for specific situations (e.g. the compareTo method in the superclass can be called if you receive anything other than an Employee, and this also holds for the equals method). The toString method only needs to append details and as such can also…arrow_forwardMake a class Person, with instance variable name, age, and gender. Make a class Employee inheritfrom Person, with extra data for salary, and hiring date. Make another class Student inherit from Person,with data for program name, level (undergraduate/graduate), and program year. Supply required methods forthe superclass and the subclasses. Make a subclass Manager from Employee, with bonus salary, andoverride the corresponding method(s). Provide toString method for the Employee class and its subclass,Manager, such that it returns employee name, type of the employment, and salary. For instance if you createan object, manager1, from Manager class, with name=”John Smith” and annual salary of $125,000 and bonusweekly bonus of $200, and then write a print statement like System.out.println(manager1); , the output willbe:John Smith, Manager, Salary = $125,000/year, Weekly bonus = $200arrow_forwardWrite the classes as shown in the following class diagram. Add a tester that asks the user for a cat, dog and a BigDog then call all of their methods. Note that Cat and Dog inherit from the abstract class Animal and BigDog inherits from Dog.arrow_forward
- Assume B is a subclass of A. Which of the statements about the following assignment is false? A a = new B(); We can assign anything to variable a that has a subtype of B. We can call on a any method defined in A. We can call on a any method defined in B. We can assign anything to variable a that has a subtype of A.arrow_forwardGiven a Student class, and UndergradCourse is a true subtype of Course, there is one method called recommend in the Student class: public class Student { public Course recommend(Course pCourseID); } Please evaluate if EACH of the method in UndergradStudent class violates the Liskov Substitution Principle. public class UndergradStudent extends Student { 1. public Course recommend(UndergradCourse pCourseID); 2. public UndergradCourse recommend(Course pCourseID); 3. public UndergradCourse recommend(Object pCourseID); 4. public Course recommend(Course pCourseID) throw SomeCheckedException;arrow_forwardWhich of the following are true? If we derive a class from an abstract class, we can select which methods we choose to implement in our derived class. Abstract classed cannot have concrete methods. We can declare an instance of an abstract class. All of the above statements are false.arrow_forward
- Implement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: Person.java, User.java, Coach.java. Do NOT include "public static void main()" method inside all of these classes.arrow_forwardMake a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of type string. Supply a method tostring that prints the manager's name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate tostring methods for all classes. Supply a test program that tests these classes and methods.arrow_forwardAn airport van shuttles passengers between the terminal and the parking garage. After 4 trips, the tank is empty, and the van needs to drive to the gas station. After it has been refilled, it will drive to the terminal. The behavior of the car depends on two states: its location (terminal, garage, or gas station), and the tank level (empty or not). Complete the following class. The constructor yields a van in the garage with a full tank.arrow_forward
- In the following there are two classes, Employee and Manager. Manager is a subclass of Employee. The implementation of Employee class is given (Note: no getter methods are provided, so you are not able to access instance variables through getter methods in the subclass). The skeleton of the Manager class definition is given. Complete the constructor method, and the toString method for the subclass (see the details below). public class Employee { private String name; private double salary; // Make an employee with a given name and salary. public Employee(String aName, double aSalary) { name = aName; salary = aSalary; } // Provide a string description of an employee. public String toString() { return "Name: " + name + "\tSalary: " + salary; } } public class Manager extends Employee { private String department; // Make a manager with a given name, salary, and department. public Manager(String name, double salary, String department) { // put your code below } // Provide a string…arrow_forwardIn the following there are two classes, Employee and Manager. Manager is a subclass of Employee. The implementation of Employee class is given (Note: no getter methods are provided, so you are not able to access instance variables through getter methods in the subclass). The skeleton of the Manager class definition is given. Complete the constructor method, and the toString method for the subclass (see the details below). public class Employee {_private String name; private double salary; // Make an employee with a given name and salary. public Employee(String aName, double aSalary) { name salary = aSalary; } // Provide a string description of an employee. public String toString() { return "Name: "tSalary: "+ salary; } } public class Manager extends Employee { private String department; // Make a manager with a given name, salary, and department. public Manager(String name, double salary, String department) { // put your code below } // Provide a string toString() { // put your code…arrow_forwardAn airport van shuttles passengers between the terminal and the parking garage. After 4 trips, the tank is empty, and the van needs to drive to the gas station. After it has been refilled, it will drive to the terminal. The behavior of the van depends on two states: its location (terminal, garage, or gas station), and the tank level (empty or not). Complete the following class. The constructor yields a van in the garage with a full tank.arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning