Concept explainers
True or false?
a. An abstract class can be used just like a nonabstract class except that you cannot use the new operator to create an instance from the abstract class.
b. An abstract class can be extended.
c. A subclass of a nonabstract superclass cannot be abstract.
d. A subclass cannot override a concrete method in a superclass to define it as abstract.
c. An abstract method must be nonstatic.
Trending nowThis is a popular solution!
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Database Concepts (7th Edition)
Starting Out With Visual Basic (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Write an abstract class, it can be anything well defined from the very basics.arrow_forwardCreate abstract class Pet , which is the abstract superclass of all animals.Declare a integer attribute called legs, which records the number of legs for this animal.Define a constructor that initializes the legs attribute.Declare an abstract method eat.Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).Create the Dog class.The Dog class extends the Pet class.This class must include a String attribute to store the name and food of the petDefine a default constructor that calls the superclass constructor to specify that all dogs have 4 legs and name.override the eat and walk method.Create the Cat class that extends Pet.This class must include a String attribute to store the name of the pet, and a string to save food .Define a constructor that takes one String parameter that specifies the cat's name and food. This constructor must also call the superclass constructor to specify that all cats have four legs.Override walk…arrow_forwardQUESTION 16 What must be true of a class with one abstract method? O The class must also implement the Iterable interface Any derived class must implement the method The abstract method must have the static modifier O The method cannot specify a return value QUESTION 17 Suppose we wanted to design a set of classes for a veterinarian's office. Our Customer class looks like this: public class Customer { Pet [] pets; } Select all the statements that are true Once the size of the pets array has been set, it cannot be changed Because we're using an array, all pets must be the same A customer must have at least one pet We also need to declare a Pet class QUESTION 18 What is the proper use of an enumeration? To define a set of ordered values To enforce the use of the Comparable interface O To define, or enumerate, the values returned by a Random object generator O To define the classes in an inheritance hierarchyarrow_forward
- Design a console program that will print details of prescribed textbooks of students. Make use of an abstract class Book with variables that will store the author, title, category and price of a book. Create a constructor that accepts the author, title and category through parameters and assign these to the class variables. Create an abstract set method for the price of a book; also create get methods for the variables.Create a subclass TextBook that extends the Book class and implements an iPrintable interface. The interface that must be added is shown below:public interface iPrintable { String DisplayDetails();}The TextBook subclass has a private variable named yearPrescribed for which a get method must be written. The constructor of the TextBook class must accept the author, title, category and yearPrescribed through parameters. Write the code for the setPrice() and DisplayDetails() methods.Write a useBook class and instantiate 2 objects of the TextBook class.arrow_forwardAn unspecified data type can be used for both the parameters and the return type just for abstract classes (because they can not be instantiated) just for the signature of a method (i.e., the parameters) O just for the non-signature parts of the method (i.e., the return type)arrow_forwardIt is necessary for a subclass of an abstract class to implement all of the abstract methods that are defined for the parent class. Is there a mistake or is it accurate?arrow_forward
- 4. Which of these is not a correct statement about abstract class? a. Every class containing abstract method must be declared abstract. b. Abstract class define only the structure of the class not its implementation c. Abstract class can be initiated by new operator d. Abstract class can be inheritedarrow_forwardIf Class A inherits from Class B, we say that Class B is the subclass and Class A is the superclass. True Falsearrow_forward1. Create abstract class Pet , which is the abstract super class of all animals.1. Declare an integer attribute called legs, which records the number of legs for this animal.2. Define a constructor that initializes the legs attribute.3. Declare an abstract method eat.4. Declare a concrete method walk that prints out something about how the animals walks (include the number of legs).2. Create the Dog class that implements Pet class.1. This class must include a String attribute to store the name and food of the pet2. Define a default constructor that calls the super class constructor to specify that all dogs have 4 legs and name.3. override the eat and walk method.3. Create the Cat class that Implements Pet class.1. This class must include a String attribute to store the name of the pet, and a string to save food .2. Define a constructor that takes one String parameter that specifies the cat's name. This constructor must also call the super class constructor to specify that all cats have…arrow_forward
- True or False a. If you do not write a constructor for a class, java will supply a default constructor. b. Java does not allow constructors to be overloaded. Abstract methods must have a void return type. d. All classes have a default equals (Object) method even if their programmer didn't write one for it. You can override a static method defined in a superclass. A method can have at most one return statement. g. A method cannot return a Wrapper class reference. h. The reserved word super can be used to access a constructor in a parent class. i. Object is an abstract class. e. f.arrow_forwardProgramming Launguage = Python 2. ShiftSupervisor Class In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Write a ShiftSupervisor class that is a subclass of the Employee class you created in Programming Exercise 1. The ShiftSupervisor class should keep a data attribute for the annual salary and a data attribute for the annual production bonus that a shift supervisor has earned. Demonstrate the class by writing a program that uses a ShiftSupervisor object. Sample Output Enter the name: John Smith Enter the ID number: 234 Enter the annual salary: 100000 Enter the bonus: 10000 Shift supervisor worker information: Name: John Smith ID number: 234 Annual Salary: $100,000.00 Annual Production Bonus: $10,000.00 Combined Annual Pay: $110,000.00 NOTE: Add new calculation.arrow_forward5. Is it compulsory for a class, which has been declared as abstract, to have at least one abstract method?arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT