Question

12. Given a class Date and a class Time, define a class DateTime1 using inheritance and a class DateTime2 using composition. Explain the advantages of each implementation.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

class DateTime1 extends Date //Example of Inharitance, is-a relationship

{

//

}

class DateTime2 //Example of composition, Has-a relationship

{

private Time time= new Time();

}

Advantages of inharitance:

  • The advantage of class inheritance is that it is done statically at compile-time and is easy to use.

Disadvantage:

  • the subclass becomes dependent on the parent class implementation.

composition advantage:

  • implementations can be replaced at run-time. ?

Disadvantage:

  • the behavior of the system may be harder to understand just by looking at the source code. ?

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Add a comment
Know the answer?
Add Answer to:
12. Given a class Date and a class Time, define a class DateTime1 using inheritance and...
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
  • 1. Discuss the difference between inheritance and composition. What are the advantages and disadvantages of each?...

    1. Discuss the difference between inheritance and composition. What are the advantages and disadvantages of each? Can you implement one with the other? 2.How is a class similar to a database table? How is it different? How do these similarities and differences justify the need for class models and for data models? Or do they? 3.Discuss the difference between association and composition. What are the advantages and disadvantages of each? 4.When would you apply inheritance? When would you not? Provide...

  • Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year....

    Using c++.Complete the implementation of the class date that represents dates written in the form day/month/year. Do not modify the main program. You must write the prototypes and the definitions of the methods of the class. Declaration of Class Date /File: date.h A class representing dates in the form: day, month and year dat e s are written to a stream in the form day/mon th / year day number () returns the number of days since 1/1 of the...

  • USE C++ Demonstrate how to write an interface for a VEHICLE class using C++. In your...

    USE C++ Demonstrate how to write an interface for a VEHICLE class using C++. In your interface, demonstrate the following (use comments to explain or for demonstration): -Interface implementation -Multiple interface implementation for a single class -Example of a Diamond Inheritance problem -Polymorphism Explain each term above clearly in the code example and discuss how it is being used USE C++

  • What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for...

    What is Multiple Inheritance and explain it using a Class Diagram and Write a Code for it in C#. Use Set() and Get() as well.

  • Examine the design class diagram and add qualifiers to each association: inheritance, interface-implementation, aggregation, composition, or...

    Examine the design class diagram and add qualifiers to each association: inheritance, interface-implementation, aggregation, composition, or just a regular navigation visibility. LiveDaracT> AddToDoActivity etends AppCompesk RecyclerView etana Viero orsmtrs fields oons tructors- impleme NieaingCN methods Databaseten Room Databace Motors ToDoViewModel ns Androidiao ToDo Bosbods ors oors tructors corstructors ToDoDao -feids FragmertAati O methods A Tasi Stac Bulde SupportParent Toggle DelegatePro ToDoRepositor fekds elds oons trutors- DateConverter ToDoAdapter extends RecyclerViex Ada MainActivity eren AppComeets fields- tfel constructors Mors in BuildConfigl imethoda...

  • Define an example of inheritance with a base class that has 2 attributes, 2 derived classes...

    Define an example of inheritance with a base class that has 2 attributes, 2 derived classes that each have 2 attributes. Implement this in C++. Create a driver program that creates instances of both of the derived classes and exercises the classes’ member functionsl. Student answer should include the following: 1 base class with 2 attributes, 2 constructors (default and with parameters), get/set methods for each attribute, and display methods 2 derived classes with 2 attributes, 2 constructors (default and...

  • UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships...

    UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships Labwork Please read all of the directions carefully. You will create a UML class diagram reflecting the class hierarchy for a fictional program that manages university personnel as constructed according to the graph displayed below. You will need to think about the attributes and behaviors that are unique to each class, and also those attributes and behaviors that are common amongst the subclasses and...

  • (15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class...

    (15)Given the following classes, how would you arrange them in an inheritance hierarchy? class Pen; class BallPoint; class Pencil; class MechnicalPencil; class WoodPencil; class WritingInstrument; class FountainPen; Draw the inheritance diagram and relate the classes via C++ code.

  • python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in...

    python 3 inheritance Define a class named bidict (bidirectional dict) derived from the dict class; in addition to being a regular dictionary (using inheritance), it also defines an auxiliary/attribute dictionary that uses the bidict’s values as keys, associated to a set of the bidict’s keys (the keys associated with that value). Remember that multiple keys can associate to the same value, which is why we use a set: since keys are hashable (hashable = immutable) we can store them in...

  • (JAVA) Using classes and inheritance, design an online address book to keep track of the names

    (JAVA)Using classes and inheritance, design an online address book to keep track of the names, addresses, phone numbers and birthdays of family members, friends and business associates. Your program should be able to handle a maximum of 500 entries.Define the following classes: Class Address to store a street name, city, state and zip code. Class Date to store the day, month and year. Class Person to store a person's last name and first name. Class ExtPerson that extends the class...

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