Question

How do you use subclassing to design simple class hierarchies that allow code to be reused...

How do you use subclassing to design simple class hierarchies that allow code to be reused for distinct subclasses? (250 own words)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

what is subclass:

classes can be derived from other classes. The derived class is called a subclass.

The class from which it's derived is called the superclass.

The object oriented paradigm supports code reuse through inheritance. classes exist in a object oriented language in a class heirarchy.

A class can be declared as a subclass of another class,which is called the parent class.which is called as parent class or super class.

inheritance comes into two varieties:single inheritance and multiple inheritance.

in single inheritance the class hierarchy from a tree rooted in the most general class.

Single inheritance enables a derived class to inherit properties and behavior from a single parent class. It allows a derived class to inherit the properties and behavior of a base class, thus enabling code reusability as well as adding new features to the existing code.

in multiple inheritance : which allows class to be a subclass of one or more superclasses.

Multiple Inheritance is a feature of object oriented concept, where a class can inherit properties of more than one parent class. The problem occurs when there exist methods with same signature in both the super classes and subclass. On calling the method, the compiler cannot determine which class method to be called and even on calling which class method gets the priority.

if you have any doubts ask me.... thank you

Add a comment
Know the answer?
Add Answer to:
How do you use subclassing to design simple class hierarchies that allow code to be reused...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • There are design imperfections with this code. relating to encapsulation (in terms of the class), and...

    There are design imperfections with this code. relating to encapsulation (in terms of the class), and something to do with how age is calculated being rigid (in terms of it only works for 2019, and will break next year). Improve the design of this code, and add a short comment or two up the top explaining what you've done and why. code: class Student: def __init__(self, firstName, lastName, birth_year): self.name = firstName + " " + lastName self.birth_year = birth_year...

  • Use Visual Studio for the following: Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing...

    Use Visual Studio for the following: Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is a kind of CommissionEmployee with the following differences and specifications: HourlyPlusCommissionEmployee earns money based on 2 separate calculations: commissions are calculated by the CommissionEmployee base class hourly pay is calculated exactly the same as the HourlyEmployee class, but this is not inherited, it must be duplicated in the added class BasePlusCommissionEmployee inherits from CommissionEmployee and includes (duplicates) the...

  • (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal a...

    (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...

  • Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design...

    Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...

  • THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU....

    THIS IS IN THE JAVA SCRIPT CODE ALSO PLEASE SEND ME THE CODE TYPED THANK YOU. Program 1 Write an inheritance hierarchy of three-dimensional shapes. Make a top-level shape interface that has methods for getting information such as the volume and the surface area of a three-dimensional shape. Then make classes and subclasses that implement various shapes such as cube, cylinders and spheres. Place common behavior in superclasses whenever possible, and use abstract classes as appropriate. Add methods to the...

  • How do you determine the relationship between 2 variables? And how do you use simple linear...

    How do you determine the relationship between 2 variables? And how do you use simple linear regression to describe and test whether this relationship is significant?

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Create your own unique While-End or (For End) repetition C code. You decide the theme. Be...

    Create your own unique While-End or (For End) repetition C code. You decide the theme. Be sure to provide an overview of what your repetition structure is doing. Please keep the design simple for this exercise. Just a few lines of code is all that is needed for this response. This should be code you wrote for an application that is interesting to you. In other words, make it your own and have fun with it. Provide the C code...

  • 1. What is the structure of a relational database? How do you implement a simple relational...

    1. What is the structure of a relational database? How do you implement a simple relational database in Python and what are some of the benefits? 2. What is the purpose of the “self” argument in the method definitions of a class 3.What does operator-overloading mean in Python? Give an example. 4.Describe the meaning of polymorphism in Object Oriented Programming. Give an example of polymorphism and how it works when the program is executing. 5.What is inheritance in object-oriented design?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT