Concept explainers
Suppose Fruit, Apple, Orange, GoldenDelicious, and McIntosh are defined in the following inheritance hierarchy:
Assume the following code is given:
Fruit fruit = new GoldenDelicious();
Orange orange = new Orange();
Answer the following questions:
a. Is fruit instanceof Fruit?
b. Is fruit instanceof Orange?
c. Is fruit instanceof Apple?
d. Is fruit instanceof GoldenDelicious?
e. Is fruit instanceof McIntosh?
f. Is orange instanceof Orange?
g. Is orange instanceof Fruit?
h. Is orange instanceof Apple?
i. Suppose the method makeAppleCider is defined in the Apple class. Can Fruit invoke this method? Can orange invoke this method?
j. Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Can Fruit invoke this method?
k. Is the statement Orange p = new Apple() legal?
l. Is the statement McIntosh p = new Apple() legal?
m. Is the statement Apple p = new McIntosh() legal?
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java How To Program (Early Objects)
Computer Science: An Overview (12th Edition)
- There are three distinct varieties of hibernation inheritance accessible.arrow_forwardJavaarrow_forwardObject Oriented Programming in JAVA You are part of a team writing classes for the different game objects in a video game. You need to write classes for the two human objects warrior and politician. A warrior has the attributes name (of type String) and speed (of type int). Speed is a measure of how fast the warrior can run and fight. A politician has the attributes name (of type String) and diplomacy (of type int). Diplomacy is the ability to outwit an adversary without using force. From this description identify a superclass as well as two subclasses. Each of these three classes need to have a default constructor, a constructor with parameters for all the instance variables in that class (as well as any instance variables inherited from a superclass) accessor (get) and mutator (set) methods for all instance variables and a toString method. The toString method needs to return a string representation of the object. Also write a main method for each class in which that class is…arrow_forward
- Create game characters using the concept of inheritance. Complete the program class Person { public: string profession; int age; Person (): profession("unemployed"), age(16) { } void display () { cout << "My profession is: " << profession << endl; cout << "My age is: " << age << endl; walk(); talk(); } void walk() { cout << "I can walk." << endl; } void talk() { cout << "I can talk." << endl; } }; class MathsTeacher 1 class Footballerarrow_forwardCreate a C++ console application that implements this inheritance hierarchy. Note the following: The game has no "Enemy" object but it does have specific enemies. (Abstract) All enemies will have the following properties or behaviours • Damage - A value representing how much damage they would do to an enemy. Default enemy damage is 10. • Warcry- A proclaimation of their intent to do battle. Default enemies warcry is "Roar!" . Attack - An ability to combine a warcry with damage. (Ex: "Roar!" "Deal 10 damage to opponent'). Skeleton: • Damage - Base enemy damage 0 Warcry- Base enemy warcry but with the addition of "Hssssssssssss" to the end. 0 Attack - Warcry followed by two quick attacks on the opponent. Troll: ■ Damage - 1.5x base enemy damage. ■ Warcry- Base enemy warcry but with the addition of "Grrrrr" to the end. ■ Attack - Warcry followed by a single attack on the opponent. ■ Ora: Dark Orc: ■ ■ ■ Damage - 2.0x base enemy damage. ■ Warcry- Base enemy warcry with the addition of…arrow_forwardAssuming the following is the beginning of the constructor definition for class BasePlus-CommissionEmployee which inherits from class Point, BasePlusCommissionEmployee::BasePlusCommissionEmployee( string first, string last, string ssn, double sales, double rate, double salary ) : CommissionEmployee( first, last, ssn, sales, rate ) The second line: Select one: a. Indicates inheritance b. Causes a compiler error c. Is unnecessary because the CommissionEmployee constructor is called automatically d. Invokes the CommissionEmployee constructor with argumentsarrow_forward
- Please help me with the following java. Please include inheritance. Please also include comments explaining each line of codearrow_forwardInheritance and UML (Java) Design a class named Employee. The class keeps the following information in fields: - Employee Name - Employee Number in the format XXX-L, where each X is a digit within the range 0-9 and the L is a letter within the range A-M. - Hire Date - Shift (an integer) - Hourly pay rate (a double) Write one or more constructors and the appropriate accessor and mutator methods for the class. The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift1 and the night shift is shift 2. a) Draw a UML diagram of the class. Be sure to include notation showing each field and method’s access specification and data type. Also include notation showing any method parameters and their data types. b) Write a program that demonstrates the class.arrow_forwardbuild a student class implement the student class with the following instance variables: * id * firstName *lastName *dateOfBirth * Major create an __init__ function adn initialize all the fields make the "major" an option field and set a default value to "undefined" create a setter and getter function for all these five variables create another function: "print_student_info()" which prints 5 pieces of information: id, first name, last name, date of birth, and major. Make sure to have proper formatting done for printing these 5 things. Use the student class Task 1: create an empty list named "all_students" Task 2: create a variable named "id" and initialize it to 100 (some default value to start with, next id would be 101) Task 3: ask the user for input "How many students:" Task 4: Now run a for loop based on that input number and do the following things for each iteration: - get input of student's first name, last name, date of birth, and major - user should be able to skip the…arrow_forward
- Writing the setbank functionsSetbalanceSetaccontIn order to enter the creditcard data instead of entering it into the constructor functionand execute it in the main class public class CreditCard { private String customer; private String bank; private String account; protected double balance; public CreditCard(String cust,String bk, String acnt,double initialBal) { customer=cust; bank=bk; account=acnt; balance=initialBal; } public CreditCard(String cust, String bk, String acnt) { this(cust,bk,acnt,0.0); } public String getCustomer() { return customer; } public String getBank() { return bank; } public String getAccount() { return account; } public double getBalance() { return balance; } // Update methods: public void charge(double price) { // make a charge balance += price; } public void makePayment(double amount) { // make a payment balance -= amount; }…arrow_forwardClasses: Write a Person class that has these attributes: person_ID, first and last names, and age Default and overloaded constructors Accessors and mutators equals method toString method (make this virtual if C++, don't forget to prep the class for polymorphism) Inheritance: Create a child class to Person called Student: Attributes: GPA and status (freshman, sophomore, junior, senior, graduate, graduated). Make sure you have appropriate accessor/mutator methods Create another child class to represent Faculty. This class will have faculty rank and length of service as attributes along with an office location. Again, add methods as needed. Application Create an application that displays a menu that allows users to add students or faculty, or print either one or exit. Deliverable: Submit your source code and classes on Github (you will be supplied an account) You will also submit a Word document and your code on Canvas. In the document you iwll write a summary of your design…arrow_forwardUse the Animal class file given on the final exam module. Use Inheritance and Polymorphism concepts to create the following classes and functions. Create the following classes that derive from the Animal class. Monkey Kangaroo Create a derived class named Spider Monkey whose base class is Monkey. Create constructors for each class. Create destructors for each class. All classes will have the following private instance fields, including Animal legs that will initialize to 0 boolean swim that will initialize to false; All classes will have the following polymorphic methods, including Animal getLegs( ) – this returns the number of legs the animal has makeSount( ) – this outputs the type of sound the animal makes makeSound( ) method will be a virtual function in the Animal class Create an exception in the getLegs( ) method that makes sure the number of legs are valid (only allow positive number amount of legs) Create a main method to demonstrate the all functions including the…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage