Question

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

Homework Answers

Answer #1

Choice(2) is correct, i.e., when the inheriting class is closely related to the abstract class, such as with an "is-a" relationship.

Expalantion :

Class declared as abstract can't be instantiated directly, that is, instantiating abstract class using new keyword is not supported. A method inside the abstract class should not be defined and can only be declared. A good way of accessing abstract class is to create a concrete class(class which inherits the base, that is, abstract class)and further this class should be used to define the abstract methods present in abstract class. So, 'is-a' relationshiop which provides code reusability feature by providing inheritance functionality will be implemented.  

Know the answer?
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
Similar Questions
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If...
Goal:   Manage the inventory of objects sold in an online or brick and mortar store. If you can't implement all of the features of Project described in this document, implement what you can. Start by implementing the StockItem class, and its derived classes. Then add in the InventoryManager class later. In each case, the test files must be in separate classes. UML Diagram: Use Violet or other drawing software to draw the UML diagrams of each class that you use...
PLEASE FILL IN THE BLANKS WITH THE PROPER TERM! THANKS Key Terms ---------------------------------------------------------------------------------------------------------------------------- Positive relationship ---...
PLEASE FILL IN THE BLANKS WITH THE PROPER TERM! THANKS Key Terms ---------------------------------------------------------------------------------------------------------------------------- Positive relationship --- Occurs in so far as pairs of observations tend to occupy similar relative positions in their respective distribution. Negative relationship --- Occurs in so far as pairs of observations tend to occupy dissimilar relative positions in their respective distribution. Scatterplot --- a graph containing a cluster of dots that represents all pairs of observations. Person correlation coefficient --- A number between –1 and +1...
Compile and execute the application. You will discover that is has a bug in it -...
Compile and execute the application. You will discover that is has a bug in it - the filled checkbox has no effect - filled shapes are not drawn. Your first task is to debug the starter application so that it correctly draws filled shapes. The bug can be corrected with three characters at one location in the code. Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the...
Read the following three situations. Describe what you would do in EACH situation. Integrate the elements...
Read the following three situations. Describe what you would do in EACH situation. Integrate the elements of reasoning and intellectual standards in your writing to show an understanding of the material behind your personal example Your essay should be 500-750 words in length and include the use of at least two (2) elements of reasoning and two (2) intellectual standards for EACH of the three (3) scenarios you will be discussing. Do not worry about your answers being right or...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote...
TrackMinMax For this lab, you will create a generic version of the IntTrackMinMax class you wrote in a previous lab, called TrackMinMax. The API is: Function Signature Description constructor TrackMinMax() constructor check void check(T i) compares i to the current minimum and maximum values and updates them accordingly getMin T getMin() returns the minimum value provided to check() so far getMax T getMax() returns the maximum value provided to check() so far toString String toString() returns the string "[min,max]" As...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT