Java "class" and inheritance recitation
This recitation is an introduction to creating your own Java classes.
The context will be products in a store similar to products in the
program 4 online store. Products would include, food, soaps, cleaning
supplies, clothe, electronics, toys, etc.
Why an example about store products? Using products is helpful for
demonstrating inheritance. The concept of inheritance enables making
relationships between similar classes. Specifically, a sub-class
inherits the data and methods from the super-class. In our example the
Product class is a generic product (the super-class). Other products
(sub-classes), such as produce and member discount products, are
similar to the generic product. These products have a name and price.
The purpose of sub-classes, however, is to model the details that
differ from the generic product. In our example the cost of all three
kinds of products varies.
Parts:
- Create the Product class
- Using Product class in a main program
- Product class. public/private
- Produce sub-class
- Member sub-class
Solution