Question

In: Computer Science

Which of the following situations described is a good situation to use an abstract class, and...

Which of the following situations described is a good situation to use an abstract class, and where it would be better to use than either a concrete class or an interface?

When some methods in the class are abstract and some are concrete, and some variables in the class need to be private, while other variables need to be public

When the inheriting class is closely related to the abstract class, such as with an "is-a" relationship

When the objects instantiated from the abstract class hierarchy need to be grouped together

When the class will have both concrete and abstract methods

All of the above are reasons to use an abstract class over a concrete class or an interface

Solutions

Expert Solution

All of the above reasons are to use an abstarct class over a concrete class or interface

Explanation:-

--Abstract class os a class declared abstract

-- It may or may not contain abstract methods

-- Abstract classes cannot be instantiated but it can be subclassed

-- If a class contan abstract methods , the class itself must be declared abstract

Eg:- public abstract class Person {

// variable declaration

// declare non abstract methods

abstract void Home Address ();

}

-- Abstract classes are similar to the interfaces. You cannot instantiate them. They may contain a mix of methods declared with or without implementation

-- In abstract class you can declare fields that are static and final define public, protected, private concrete methods. With interface all fields are automatically public, static and final and all methods that you declare or define are public

-- You can implement any number of interfaces in the abstract classes


Related Solutions

Question 1: Read the following situations and decide if the situation described is a symptom or...
Question 1: Read the following situations and decide if the situation described is a symptom or a problem. If it is a symptom, provide an example of what the underlying problem might be. If it is a problem, provide an example of what symptom we might see. Alcatel, a flip-phone manufacturer, discovers its phone's features are viewed as inadequate by target consumers. Abercrombie & Fitch discovers its sales are falling short of its goals. Time Warner Cable discovers its customer...
1. Can you extend an abstract class? In what situation can you not inherit/extend a class?...
1. Can you extend an abstract class? In what situation can you not inherit/extend a class? 2. Can you still make it an abstract class if a class does not have any abstract methods?
For the following situations given the system described, which of the quantities listed should be zero?...
For the following situations given the system described, which of the quantities listed should be zero? For those that are not zero, provide its sign. (External work, change in kinetic energy, change in gravitational potential energy, change in elastic potential energy, change in thermal energy) a. System: Ice skater. Situation: (Initial state = Ice skater at rest on ice, final state: ice skater at high speed on the ice) b. System: Ice skater + ice rink. Situation: (Initial state =...
- Class DiscountPolicy is an abstract class with a method called computeDiscount, which returns the discount...
- Class DiscountPolicy is an abstract class with a method called computeDiscount, which returns the discount for the purchase of items. DiscountPolicy knows the name of the item and its cost as well as the number of items being purchased. - Class BulkDiscount, derived from DiscountPolicy, has two fields, minimum and percentage. computeDiscount method will return the discount based on the percentage applied, if the quantity of items purchased is more than minimum. For example: if minimum is 3 and...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's cart. Items of Type T can be added * or removed from the cart. A hashmap is used to keep track of the number of items * that have been added to the cart example 2 apples or 4 shirts. * @author Your friendly CS Profs * @param -Type of items that will be placed in the Cart. */ public abstract class AbstractCart {...
Two independent situations are described below. Each situation has future deductible amounts and/or future taxable amounts...
Two independent situations are described below. Each situation has future deductible amounts and/or future taxable amounts produced by temporary differences. Situation 1 2 Taxable income $40,000 $80,000 Amounts at year-end: Future deductible amounts 5,000 10,000 Future taxable amounts –0– 5,000 Balances at beginning of year: Deferred tax asset 1,000 4,000 Deferred tax liability –0– 1,000 The enacted tax rate is 25% for both situations. Determine the income tax expense for the year. Situation 1 Situation 2 a.$10,000$20,000 b.$9,750$21,750 c.$5,000$17,000 d.$0$0
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
In which of the following situations would it be appropriate to use a paired t-test to...
In which of the following situations would it be appropriate to use a paired t-test to analyze the data? Check all that apply. A researcher was interested in the differences in attitudes towards saving money and eliminating debt between couples who are engaged to be married. As part of a premarital counseling program, 45 engaged couples filled out a survey that assessed their attitudes towards financial matters such as their priorities for saving money and eliminating debt. The researcher compared...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Derive a class BulkDiscount from DiscountPolicy. It should have a constructor that has two parameters minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more then minimum, the discount is percent percent.
Each of the following situations represent a situation at a business. Freedom estimates that $700,000 of...
Each of the following situations represent a situation at a business. Freedom estimates that $700,000 of its accounts receivable will prove to be uncollectible. The company’s president is in poor health and has previously suffered two heart attacks. As with any airline, Freedom faces the risk that a future airplane crash could cause considerable loss. Freedom is being sued for $2 million for failing to adequately provide alternative service for passengers whose reservations were canceled as a result of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT