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 (11th Edition)
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)
- The organization working on deforestation wants you to create software using your object-oriented concepts for trees. Trees has category of pine and eucalyptus. You must store information of all of these trees. Identify classes, their attributes and inheritance (if any) and implement following functionality: Input function Update info of pine tree Update info of eucalyptus Display functionarrow_forwardPTHYON: BASIC INHERITANCE Set course_student's last_name to Smith, age_years to 20, and id_num to 9999.Sample output for the given program:Name: Smith, Age: 20, ID: 9999arrow_forwardThere are three distinct varieties of hibernation inheritance accessible.arrow_forward
- Using Inheritance to Create a Derived Class in Python Summary In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status. Instructions Open the file named Motorcycle.py. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class __init()__ method inside the Motorcycle class's __init()__ method. In theMotorcycle class, create an attribute named sidecar. Write a public set method to set the value for sidecar. Write a public get method to retrieve the value of sidecar. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast".…arrow_forwardYou will define three objects class Person, BookAuthor, and Book. Class Person involves a person's identity. Class BookAuthor involves a collection of books or book titles. Class Book involves the number of books in stock , book title and price. Design the three classes: The classes must use an appropriate inheritance relationship. Each class must have a constructor. Each class has at least two private data members and you must include accessors. You must test your classes by creating a BookAuthor object and printing the Person, Book and BookAuthor values from a function you create inside of BookAuthor. Make sure you use the book object correctly and put it inside of BookAuthor. in pytgiarrow_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_forward
- build 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_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_forwardKOTLIN: Classes and Inheritance Given the Pet as the parent class of the Cat, Dog, and Fish. Complete the code so that each instance of Cat, Dog and Fish can shows their informations and action as given. //Expected output A pet named Garfield with color Orange do meow A pet named Pluto with color Black do barks A pet named Jenny with color Gold do Swimarrow_forward
- wirte a c++ program c++ 1. Student Evaluation using Inheritance TASK Step1: Create a class studentpersonal declare rollno, age, name, sex in protected mode. Step2: Using a parameterized constructor initialize the values for all the data members. Step 3: Create another class studentmark that is inherited from the base class and having the data members mark1, mark2, mark3 and mark4. Using a parameterized constructor initialize the value for mark1,mark2,mark3 and mark4. Step 4: Create another class call studentsports and declare score as protected mode. Step 5: Create a class studentresult and public inherited form studentmarks and studentsports having the data members total, avg,grade. Step6: Calculate the total and average and display the result.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_forwardThe hospital wants you to create software using your object-oriented concepts. It has nurses and doctors. You have to store information of all of these employees. Identify classes, their attributes and inheritance (if any) and implement following functionality: 1. Input function 2. Update salary of doctor 3. Update ward_no of nurse 4. Display functionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education